Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 ?

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

exit

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
1  
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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.