Hello! I have a very simple bash script that I have scheduled to run weekdaily. I tried crontab -e with 0 19 * * 1-5 bash /path/to/script.sh and I also tried sudo crontab -e with the same task. Neither work if I’m not actively working at my computer at the same time. I would appreciate any guidance on how to get cron to work even when I’m not at my computer (but it is on). Thanks!
There are multiple possible reasons why it might not work. A few would be:
/path/to/script.shisn’t accessible when you are away (e.g. if it is only mounted when you are signed in, but you are not signed in when you are away).- Your PC is suspended (to save power) in a way that it cannot check to see if any Cron jobs are scheduled and need to be run.
What does cat /sys/power/mem_sleep show?
s2idle [deep]
During suspend all processes (incl cron daemon) are stopped. rtcwake(1) might be used to schedule the wake up of the suspended OS (e.g. to run cron jobs).
In case the job fails also if the OS is running then /var/log/cron should be checked for error messages.
To get it to work like you want, you will probably need to convert your cron job to a systemd timer. Systemd timers have a WakeSystem=true option that can schedule the PC to be resumed from its suspended state so the scheduled job can run. I think support for resuming from the S3 (deep/Suspend-to-RAM) mode depends on whether the hardware supports that function, but it should work.