Hello,
I am on Fedora KDE 43, and I am pretty new to Linux, so I shouldn’t have derived too much from the original setup.
I am trying to make my computer hibernate between 9PM and 7AM, if it is not already closed.
I want to make the following cron line work:
* 0-6,21-23 * * * systemctl hibernate
The problem is, it doesn’t work.
To understand what the issue is, I also created a log file:
* 0-6,21-23 * * * systemctl hibernate >> ~/logs/log_sudo.help 2>&1
And… I receive no log entries at all.
Here is what is tried:
sudo crontab -e
returns
* * * * * echo "hey!"
* 0-6,21-23 * * * echo "Le système s'est éteint à $( date '+%F_%H:%M:%S' )" >> ~/logs/log_sudo.help 2>&1
* 0-6,21-23 * * * systemctl hibernate >> ~/logs/log_sudo.help 2>&1
The first line was to know if the simplest thing could work. It doesn’t, but maybe it is more complicated than that.
The second was to get some log entries. I didn’t get any.
The third does what I want.
If I try to open the log via
sudo nano ~logs/log_sudo.help
it shows an empty file.
I tried every line separately outside of cron. Everything works fine.
I had a few issues with swap space at first for hibernating, but now it works well.
I tried not to hibernate, but to make my computer shutdown or whatever, it doesn’t do anything.
Some people in the internet mentioned that the cron file for root is supposedly in /etc/crontab.
I opened it
sudo nano /etc/crontab
and wrote
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
* * * * * echo "hey!"
* * * * * echo "hey!" >> ~/logs/log_sudo.help 2>&1
Again, it doesn’t do anything.
Cron works for non-root users fine though:
On my account, if I write:
crontab -l
* * * * * echo "hey" >> ~/logs/log.help 2>&1
And I open ~/logs/log.help, I do see a line of 'hey’s.
What did I do wrong?
I have been stuck on this for a few days, it is pretty frustrating.
If I forgot to mention everything to help you understand the issue, please ask.