Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have an rsync command which does replication of sorts:

0 0  * * *  rsync -av --delete /media/VIDEOS/ /media/lacie1/backup/videos/

Is there a way to stop the rsync command from running if the source is not accessible (ie: not online/mounted)?

share|improve this question
Do you want this to be a silent fail or do you want to know if it's failed ? – Iain Jul 15 '11 at 9:41
The reason for this is in case something goes wrong with the source, I don't want to mess up the replication. So, stop the replication from happening if the source is not there. – David Jul 15 '11 at 12:18
up vote 2 down vote accepted

You could try

0 0 * * * cd /media/VIDEOS/ && rsync -av --delete /media/VIDEOS/ /media/lacie1/backup/videos/

which will not run the rsync command if the cd fails which it should if the source doesn't exist.

If you want it to fail silently

0 0 * * * [ -e /media/VIDEOS ] && rsync -av --delete /media/VIDEOS/ /media/lacie1/backup/videos/
share|improve this answer
I guess he wants to get rid of the error message when the backup fails. Now he will get an error message that the change directory command fails ;) – Comradin Jul 15 '11 at 9:24
@Comradin: If that's what he wants there are solutions but it's not what he asked for and nor is it impled. – Iain Jul 15 '11 at 9:26
Test if folder is mounted: grep -q '/media/VIDEOS' /proc/mounts && rsync ... – SamK Jul 20 '11 at 14:35
@SamKrieg: lots of ways to skin a cat, thats a good one to know though. – Iain Jul 20 '11 at 15:12

Souds like you're doing a midnight backup of your desktop computer and you're being spammed by the cron daemon about the failing backup.

The simple and crude solution would be to silence the cron, which can be done in two ways:

0 0 * * * rsync .. > /dev/null 2>&1

This will redirect stdout and stderr to /dev/null.. no mail from cron

Another solution is to define an empty email with MAILTO


0 0 * * * script1


0 0 * * * rsync ..

This should silence the script, too.

share|improve this answer

Your Answer


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.