linux - Check if rsync command ran successful -


the following bash-script doing rsync of folder every hour:

#!/bin/bash rsync -r -z -c /home/pi/queue root@server.mine.com:/home/foobar rm -rf rm /home/pi/queue/* echo "done" 

but found out pi disconnected internet, rsync failed. did following command, deleting folder. how determine if rsync-command successful, if was, may remove folder.

usually, unix command shall return 0 if ran successfully, , non-0 in other cases.

look @ man rsync exit codes may relevant situation, i'd way :

#!/bin/bash rsync -r -z -c /home/pi/queue root@server.mine.com:/home/foobar && rm -rf rm /home/pi/queue/* && echo "done" 

which rm , echo done if went fine.

other way using $? variable return code of previous command :

#!/bin/bash rsync -r -z -c /home/pi/queue root@server.mine.com:/home/foobar if [ "$?" -eq "0" ]   rm -rf rm /home/pi/queue/*   echo "done" else   echo "error while running rsync" fi 

see man rsync, section exit values


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -