Problem with crontab reboot

Latest response

Hi,

I try to schedule a reboot of one server with crond and this command line :
00 12 12 * * [ "$(date '+\%u')" -eq 0 ] && /sbin/reboot

It works on some server but not in this one.
I see that cron execute the command line , but the serveur doesn't reboot.

grep boot cron

Jun 12 12:00:02 lxsar37 CROND[7307]: (root) CMD ([ "$(date '+%u')" -eq 0 ] && /sbin/reboot)

who -b

     d▒marrage syst▒me 2016-03-22 05:35

cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.7 (Santiago)
#

Does anyone can help me?
Best regards.

Responses

sorry for the bold command line.

Hi David,

The "\" is bothering you:

[ "$(date '+\%u')" -eq 1 ] && echo a
bash: [: \1: integer expression expected

Without "\":

vdi9093.eu.asml.com:~ > [ "$(date '+%u')" -eq 1 ] && echo a
a

Hi, That's not the problem, in crontab you must escape de "%" with "\". I try with the 2 syntaxes and without "\", crond don't see the end of the command line Jun 13 14:12:01 lxsar37 CROND[25898]: (root) CMD ([ "$(date '+) Jun 13 14:12:01 lxsar37 CROND[25897]: (root) CMD ([ "$(date '+%u')" -eq 1 ] && touch /tmp/test)

Sorry, I just checked via an interactive shell and ignored the cron context.

Redirected in cron stderr of the date command (with "\%u") to a file and the message is: date: invalid date `%u' I am not sure which limitation of the environment of cron jobs is causing this.

The command date is not the problem, The redirection of standard output and error give me no error message Jun 15 15:07:01 lxsar37 crond[5998]: (root) RELOAD (/var/spool/cron/root) Jun 15 15:07:02 lxsar37 CROND[27210]: (root) CMD (date '+%u' 2>&1 >/tmp/test4) Jun 15 15:07:04 lxsar37 crontab[27212]: (root) LIST (root) [root@lxsar37 ~]# cat /tmp/test4 3

The problem seems to be with the reboot command. I will try shutdown.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.