1

I intend to put my computer to sleep every night and make it wake up again next morning. I found that rtcwake would serve my purpose. However putting it in the crontab does nothing. Following is my crontab entry for "root" user

0 1 * * * rtcwake -m disk -s 25200

I added it using 'sudo crontab -e'. The syslog shows that it executed the command, but the computer does not sleep. If I run the command on terminal directly, the computer is put to sleep immediately as expected. So I don't think there is any problem with ACPI.

Does anyone have a clue? I am on Ubuntu 14.04

2

Okay, I think I've found the solution. Adding a sudo before rtcwake solves the problem.

I now however have following question: Why does a root's crontab need sudo to run a command. Isn't it already running under root?

  • Did you ever discover why you needed to use sudo to run rtcwake via cron? – Kevin Ashcraft Oct 10 '15 at 4:06
1

I did some investigation on this, if your did "sudo crontab -e" with rtcwake inside the table without sudo, you will get the error message:

/home/leo/autojob: line 4: rtcwake: command not found

it seems that although "sudo crontab -e" is executed under root account, it cannot find the right command path. There are some other post says you shall put PATH in front of crontab etc. As long as you put sudo in front of your rtcwake command, it seems be able to find the command again.

# m h  dom mon dow   command
40 14 * * * sudo /home/leo/autojob >> /home/leo/cron_log 2>&1

the above config in sudo crontab now works, the "autojob" is the script contains the rtcwake.

  • You could also probably just substitute rtcwake for the actual full path (in my case, /usr/sbin/rtcwake). That would potentially remove the need for sudo. – voithos Aug 16 '16 at 3:38
0

I know this is two years too late, but I had the same problem and want to give my solution to anyone who might have this problem in the future.

To wake my machine up every day at 06:00, I set up a cronjob using rtcwake. My problem was, however, that even though the cronjob ran, it didn't set the alarm. I did edit the root user's crontab with sudo crontab -e.

The solution was to use the full path of rtcwakein the crontab, not just the command. To do this, first use which rtcwake which'll return the full path of the command (in my case that was /usr/sbin/rtcwake) and use that in the cronjob.

My cronjob now looks like this: 0 12 * * * /usr/sbin/rtcwake -m no -t $(date +\%s -d 'tomorrow 0600')

 

As a side note, if you're using date like me, you have to escape the percentage sign.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.