I would like to have a rsync shell script that the user will enter the folder or file to sync to another server.

i.e. - ./deploy /html/ or ./deploy /html/kuky.txt

the script will wait for the input and then will execute the rsync script please help.


Here you go:

echo "Enter file or folder path"

read target

if [ ! -e "$target" ]
    echo $target does not exist
    echo Transferring $target
    rsync -avzr $target user@example.com:/home/user/target_directory

put this into a file called sender.sh. Then call bash sender.sh from command line.

I suggest you look up options of rsync command. They may change behavior a great deal.


Can's answer requires a user to run the script and then type the path manually, the following will allow you to use the syntax you specified in your OP:


echo -n "Transferring ${*} to server... "
rsync -az ${*} <user>@<server>:/path/to/target/ 1> /dev/null
echo "Done!"

This script will take all CLI arguments given to it as source directories/files, and send them to the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.