From man page of crontab.
string meaning
------ -------
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
So a job @daily will never be executed if the system is always shutdown at midnight? What is the proper way to specify that I want to run this job once daily but I don't care when exactly it is executed in a day?
cron jobs run while the computer is on & not sleeping, so it will run in situations 1 and 2. If the computer is off or asleep at the job's scheduled time, it does not do any sort of catch-up run later when the computer restarts/wakes up; therefore, it will not run in situation 3.
cron doesn't execute while the computer is asleep. So cron can't wake your system.
cron is a process which deals with scheduled tasks whether you are logged in or not. It is not necessary to have a screen or tmux session running since the cron daemon will execute the scheduled tasks in separate shells.
The cron daemon will start cron jobs scheduled with @reboot as soon as the daemon has started after system boot. It does not matter whether any user has had the time to log in on the newly rebooted system or not or whether the job belongs to the root user or any other user on the system.
The job may run, but probably won't complete. cron is implemented via a daemon, so it's always running. Depending on your system's shutdown order, cron may actually be sent the shutdown signal fairly late in the shutdown process, so jobs scheduled for the moment the shutdown started may still run.
e.g. If the shutdown starts at 00:00:00 exactly, but doesn't get to sending cron a kill signal until 00:00:05 (5 seconds after midnight(, then a short running 2-second job may still have time to complete.
However, if any services that job depends on have already been shutdown or are in the process of shutting down, then it's unlikely to be able to finish. e.g.... the script pings a mysql server for one little piece of data... but mysql shut down at 00:00:01 and your script didn't get to the mysql portion until 00:00:02.
tl;dr: it's a race condition and your job MAY execute, but probably won't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With