Crontab and system sleep

barrowcroft

New Member
Joined
Jan 8, 2025
Messages
10
Reaction score
3
Credits
83
Am I correct in thinking that crontab will only run jobs if the system is awake and will not itself wake the system if jobs are waiting.
How would that normally be handled; suppose, for example, i want to run clamav on the whole system at midnight.
I have been trying to use systemd service and timers, but run into problems.
thanks
 


Am I correct in thinking that crontab will only run jobs if the system is awake and will not itself wake the system if jobs are waiting.
That's correct but IIRC unlike systemd crontab will run tasks that were missed due to system being shut down soon after boot up.

Timers don't do this by default, I forgot how to make them run missed tasks on boot.
 
Thanks for that, but I am not really wanting to run tasks later if they are missed. I want them to run on time or not at all. My problem is making sure the system is awake. That's why I was originally trying a timer.
 
I want them to run on time or not at all. My problem is making sure the system is awake.
This already works, all you need is to prevent computer going to sleep which can be configured somewhere in desktop settings.
You can't wake up computer at certain time.

Or you can modify crontab or systemd unit to run at different time.
 
Perhaps Ill look at that approach, but I'd rather do this without reference to a desktop environment. Either way, thanks for the suggestions.
 
Thanks for that, but I am not really wanting to run tasks later if they are missed. I want them to run on time or not at all. My problem is making sure the system is awake. That's why I was originally trying a timer.

You can disable power-saver/sleep mode/hibernation all together.

I'd rather do this without reference to a desktop environment.

If you only have a command line installed, usually the system will never sleep. (Not always true)

To check your system
Code:
cat /sys/power/state

Code:
systemctl status sleep.target
systemctl status hibernate.target

Ideally, these will say the service is dead.

root@devNUC1:~# systemctl status sleep.target
○ sleep.target - Sleep
Loaded: loaded (/usr/lib/systemd/system/sleep.target; static)
Active: inactive (dead)
Docs: man:systemd.special(7)
root@devNUC1:~# systemctl status hibernate.target
○ hibernate.target - System Hibernation
Loaded: loaded (/usr/lib/systemd/system/hibernate.target; static)
Active: inactive (dead)
Docs: man:systemd.special(7)

You can check to see if your system has ever slept or hibernated.

Code:
journalctl | grep -i "suspend\|hibernate"
 
You might look into anacron which will run a job that has been missed, unlike cron. You would still need to "wake up" your computer for this to work though. You could just keep your computer awake all the time, but just use a screen blanker instead.

I used to have trouble with my KDE desktop session locking me out after a while so I got into KDE's system settings to change that. Look for /usr/bin/systemsettings5

Signed,

Matthew Campbell
 
You could just keep your computer awake all the time, but just use a screen blanker instead.
By screen blanker, I would assume that the 'screensaver' in Linux Mint would do that job.

It presents a 'blank' screen, with only the date etc roaming around it ...otherwise the PC is awake.
 

Members online


Top