0

Every time I start my raspberry pi, I want to update and upgrade it. No other cronjob should be run before this is finished. My crontab looks like this now

@reboot sudo apt-get update && sudo apt-get upgrade -y
*/9 * * * * (python script1.py) &
*/4 * * * * (python script2.py) &

How do I make script1 and script2 wait?

1 Answers1

1

Cron does not allow / provide a native mechanism to schedule or delay a second job until the first one completes successfully.

The typical solution is to create 1 cron job that calls a single shell script and in that script you execute both jobs, one after the other, and check the exit status of the first to prevent the second from starting if case the first failed.

Or add lock file logic to each of the jobs that will ensure that a first run of your batch will simply exit without executing your actual cron job if the dependency still holds the lock https://serverfault.com/a/82863/546643

In your case, rather than using cron to update your server, do that from a dedicated start up job (in systemd) and delay the cron daemon from starting until that update job completes.

Bob
  • 5,335
  • 5
  • 24