I'm relatively new to Linux and I'm working on a CronTab for scheduled backups.
I figured out how to do multiple sequential jobs with ;
and &&
, but I'm unsure how the dependency affects the sequence.
My cron job looks like this:
# Every day at 0:00 (reboot server and do the hourly backup procedure).
0 0 * * * sh shutdown.sh && sh backup.sh ; sh nas.sh ; sh ftp.sh ; sh startup.sh
What I want to happen is to run shutdown.sh and continue the sequence if it's successful, but cancel it if it fails. My fear is it will only skip sh backup.sh
but then continue the sequence.
Will it work as intended? If not, would something like shutdown && (backup ; nas ; ftp ; startup)
be possible?
Best Answer
Why don't you test it with some dummy commands that you know will work or fail?
So it seems like your intuition was correct, and you need the second structure.
As suggested by mikeserv, for testing in general, you can use
true
(or:
) andfalse
, instead ofls
of a non-existent file. Hence,