David Asked: 2011-07-16 01:09:31 +0800 CST2011-07-16 01:09:31 +0800 CST 2011-07-16 01:09:31 +0800 CST stop rsync if source isn't accessible 772 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)? backup linux rsync 2 Answers Voted Best Answer Iain 2011-07-16T01:19:24+08:002011-07-16T01:19:24+08:00 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/ Comradin 2011-07-16T01:32:59+08:002011-07-16T01:32:59+08:00 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 MAILTO=root 0 0 * * * script1 MAILTO= 0 0 * * * rsync .. This should silence the script, too.
You could try
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
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
MAILTO=root
0 0 * * * script1
MAILTO=
0 0 * * * rsync ..
This should silence the script, too.