Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
You have a low answer acceptance rate. –  ewwhite Nov 20 '11 at 17:50

2 Answers 2

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.

share|improve this answer
    
thank you! it works!! –  edotan Nov 20 '11 at 18:50

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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