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.

link|improve this question

71% accept rate
You have a low answer acceptance rate. – ewwhite Nov 20 '11 at 17:50
feedback

2 Answers

up vote 4 down vote accepted

Here you go:

echo "Enter file or folder path"

read target

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

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.

link|improve this answer
thank you! it works!! – Elad Dotan Nov 20 '11 at 18:50
feedback

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:

#!/bin/bash

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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