Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need some hints on my first shell-script using rsync. I use rsync, because I had some trouble with a graphical Backup that ran twice and now I want this example as shown below to work on two external hard disks, including the cron job, every ten minutes. I read many examples of rsync-scripts and downloaded some, but this one I'm trying to create comes close to what I need. So I'd like to know if there is something to improve here? And do I need to mention exit=0 ?

# bash check if directory exists
if [ -d $/home/andi/Desktop/12tilt.txt ]; then
    echo "Directory exists"
    echo "Directory does not exists"


rsync -avi --progress --delete --iconv -t --stats --compress-level=0 /home/wurzel/ /mnt/usb1/home/wurzel/holz1
rsync -avi --progress --delete --iconv -t --stats --compress-level=0 /home/wurzel/ /mnt/usb2/home/wurzel/holz1
share|improve this question
I’m not clear what you’re showing us here. (A) Why does it exit before doing anything? (B) Why does it check /home/andi and then backup /home/wurzel? … – Scott Jan 11 '13 at 0:00
… And then, (1) $/home/andi/Desktop doesn’t make sense. I guess you mean either /home/andi/Desktop (without the $) or $HOME/Desktop (capital HOME with no / between the $ and HOME). (2) Do you really have a directory named 12tilt.txt? If so, that’s a very peculiar naming convention. … – Scott Jan 11 '13 at 0:01
… (3) Whenever you reference a shell variable (e.g., $HOME), it’s safest to put it –– and, optionally, the entire “word” containing it –– in double quotes, e.g., if [ –d "$HOME/Desktop/Desktop/12tilt.txt" ], to protect against the possibility that its value contains white space (unlikely for $HOME, but possible). (4) (ties back in to (A)) It probably makes more sense to exit (only) if the directory that you’re checking for doesn’t exist. – Scott Jan 11 '13 at 0:02

You must log in to answer this question.

Browse other questions tagged .