Crontab and RTCwake

New to Debian (Or Linux in general)? Ask your questions here!

Crontab and RTCwake

Postby Detzi » 2019-03-09 10:55

Hi There,
i am trying to get a crontab with rtcwake working on my debian 9 ssh server.
When i type in the line as i have written it in the su's crontab, it gets executet and works, but when the time comes the crontab should execute it, it just does nothing. I added a debug output to the line in the crontab, but the file never gets createt. Other commands in the crontab are executetd thou and run fine.
Because i get no output from the cron and the cmd itsself seems to run fine i ran out of options i know of to start digging. I attached the whole crontab i use on the server but the two lines in questions are:
Code: Select all
30 20 * * 1-5 /usr/sbin/rtcwake -m off -u -t $(date +%s --date='tomorrow 06:30') > /home/mr87/rtcwake_wd.log 2>&1

Code: Select all
00 07 * * 6-7 /usr/sbin/rtcwake -m off -u -t $(date +%s --date='tomorrow 06:30') > /home/mr87/rtcwake_we.log 2>&1


The first line should power off the system Monday to Friday at 20:30 and turn it on again 06:30 the next day.
The second line should power off the system Saturday to Sunday at 07:00 and turn it on again 06:30 the next day.

What's wrong? I can't spot it.

Thanks in advance for having a look!

Code: Select all
y
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
PATH=/usr/bin/python:/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/bin
35 06 * * * reboot
55 07 * * 1-5 /home/mr87/stockscraper/autoscrape.sh > /home/mr87/starter.log 2>&1
30 20 * * 1-5 /usr/sbin/rtcwake -m off -u -t $(date +%s --date='tomorrow 06:30') > /home/mr87/rtcwake_wd.log 2>&1
00 07 * * 1-5 /home/mr87/Reader/Reader.sh > /home/mr87/ax7.log 2>&1
00 10 * * 1-5 /home/mr87/Reader/Reader.sh > /home/mr87/ax10.log 2>&1
02 09 * * 1-5 /home/mr87/Reader/Reader.sh > /home/mr87/ax9.log 2>&1
00 20 * * 1-5 /home/mr87/Reader/Reader.sh > /home/mr87/ax10.log 2>&1
00 07 * * 6-7 /usr/sbin/rtcwake -m off -u -t $(date +%s --date='tomorrow 06:30') > /home/mr87/rtcwake_we.log 2>&1
Detzi
 
Posts: 7
Joined: 2017-11-06 06:32

Re: Crontab and RTCwake

Postby pylkko » 2019-03-09 19:50

According to the manual of crontab:

The manual wrote:Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

https://manpages.debian.org/jessie/cron ... .5.en.html


..and other similar possible problems, perhaps you can try to enter the commands into a script file that cron executes making the process thus simpler
User avatar
pylkko
 
Posts: 1597
Joined: 2014-11-06 19:02

Re: Crontab and RTCwake

Postby Detzi » 2019-03-12 20:04

Thank you,
it seems to be indeed some sort of "typo". I copied this line
Code: Select all
0 12 * * * /usr/sbin/rtcwake -m no -t $(date +\%s -d 'tomorrow 0600')

from "eirik-ff"'s answer under https://askubuntu.com/questions/499728/rtcwake-cron-does-not-work and it works.

So shell-scripts seem to be the safe option when dealing with crontabs.
Detzi
 
Posts: 7
Joined: 2017-11-06 06:32

Re: Crontab and RTCwake

Postby pylkko » 2019-03-12 20:11

No, I am not sure you understand. You need to escape the character if you do not want it to be interpreted but taken literally and passed on, like is said in the manual. Escaping in UNIX and Linux is generally done with the \ sign (as stated in the manual entry also). But, yes often it is just more easier to follow if all the stuff is dumped into a script and that script is launched. Also, while systemd timers are significantly better than cron (people should stop using cron), you still need to do escaping when passing the commands to the shell from a service file.
User avatar
pylkko
 
Posts: 1597
Joined: 2014-11-06 19:02

Re: Crontab and RTCwake

Postby Detzi » 2019-03-12 20:16

Yes but the '\' alone doesn't fix it. I understood that the crontab is reading the "%" as a lineend. Given that the crontab has its own rules on how to express the command i called it "typo".
Detzi
 
Posts: 7
Joined: 2017-11-06 06:32


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable