cron and crontab problem

Jose Bredariol
Jose Bredariol used Ask the Experts™
on
I´ve create this file : /home/user/rest.sh  (rwxr-xr-x).
------------------------------
#!/bin/bash
#rest.sh

shutdown -r now
-----------------------------

Edited the crontab file with crontab -e command.
inserted this line :

30 14 * * * /bin/sh /home/user/rest.sh

But the computer didn´t restart. What I´m doing wrong /
I´m using Debian Wheezy
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Keep in mind, this will only work in the root CRON file, never a non-super user account.

Only root (and other admin accounts) have privilege to run shutdown.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
Unprivileged user cannot do this,

either you need to use sudo (as an admin account) to run reboot /shutdown -r , or install this entry under the root user.
Also be aware that the regular path is NOT available in active cron jobs.

It is a good practice to qualify the command with full pathname.
shutdown is also in /sbin which might not be in the default path...
(You should receive a mail upon failure.)
Fractional CTO
Distinguished Expert 2018
Commented:
I'm with noci. Not a requirement + using /sbin/shutdown ensures no other shutdown command in $PATH gets picked up.

This is unlikely + if it does occur, it's a nightmare to debug.

Absolute/Full paths are your friend.

Author

Commented:
Thanks all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial