- Welcome to Geeksww.com
Script to transfer files to remote server with verification
Here is a bash script that uses rsync to transfer a set of files to another remote server and verifies the contents were transferred correctly:
#!/bin/bash # Set the source and destination directories src_dir="/path/to/local/files" dst_dir="/path/to/remote/files" # Set the hostname and username for the remote server hostname="remote_server" username="remote_user" # Use rsync to transfer the files rsync -avz $src_dir $username@$hostname:$dst_dir # Check the exit code of the rsync command to make sure it completed successfully if [ $? -eq 0 ]; then # The rsync command completed successfully, so now we will compare the contents of the source and destination directories # to make sure they are the same if cmp -s "$src_dir" "$dst_dir"; then # The contents of the directories are the same, so the transfer was successful echo "Transfer successful" else # The contents of the directories are different, so the transfer was not successful echo "Error: Transfer failed, contents of directories do not match" fi else # The rsync command failed, so the transfer was not successful echo "Error: Transfer failed" fi
This script transfers the files from the src_dir directory on the local machine to the dst_dir directory on the remote server using rsync. It then checks the exit code of the rsync command to make sure it completed successfully. If the rsync command was successful, the script compares the contents of the src_dir and dst_dir directories to make sure they are the same. If the directories are the same, the transfer is considered successful. If the directories are different, or if the rsync command fails, the transfer is considered not successful.
Did this tutorial help a little? How about buy me a cup of coffee?
Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.
IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.
tags cloud
popular searches
free download for mysql database server 5.1.5, bison, gearman, source code, php, install cairo, laptop, java, mysql, install mysql, linux, mysql initialization, mysql mysql, tools, ubuntu
Similar Tutorials:
- Installing m4 Macro Processor on Ubuntu Linux
- Debian Linux Installation and Hardening (3.1r0a)
- Download, configure, compile, and install MySQL 5.6
- Configuring Ubuntu Linux After Installation
- How to download, compile, and install CMake on Linux
Tutorials in 'Operating Systems > Linux' (more):
- Bash script to compare remote directory's files using file size
- setfacl: command not found
- How to download, compile, and install CMake on Linux
- How to download, compile, and install GNU ncurses on Debian/Ubuntu Linux?
- How to install libevent on Debian/Ubuntu/Centos Linux?
Comments (write a comment):
0 comments so far. Be the first one to leave a comment on this article.
leave a comment