0

for a five thirty pm shutdown, should I change this:

30 02 * * * /sbin/shutdown -h now

to:

30 17 * * * /sbin/shutdown -h now

see also:

Crontab Shut down command didn't work

Thufir
  • 4,551
  • is this correct? sysadmin@arrakis:~$ sysadmin@arrakis:~$ cat /etc/cron.d/anacron # /etc/cron.d/anacron: crontab entries for the anacron package SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 30 7 * * * root start -q anacron || : 30 17 * * * root /sbin/shutdown -h now sysadmin@arrakis:~$ – Thufir Oct 18 '14 at 19:54
  • 1
    I have updated the answer. – heemayl Oct 19 '14 at 08:00

1 Answers1

2

Yes, that's correct. Note that only root can run the shutdown command by default. So, if you have not done any tweaking with the permission of running the command just put the cron entry in the root user's cron (sudo crontab -e) or add the entry in /etc/crontab mentioning the user as root.

EDIT (Regarding Anacron): Absolutely bad idea. generally anacron is used while you want to run a command daily but you are not sure whether your computer will be On or Off. So lets say you have added an anacron entry to run a command. Then if the computer is On anacron checks and runs the command, if the computer was Off on that specified time the instant you turn On the computer next time anacron will run that command.

So, in a nutshell anacron is used while you are not sure your computer is gonna be On or Off. In your case you are shutting down the computer so if you put that to run by anacron your computer will be shut down by anacron if it was off and when you will turn it On after the specified time.

Your command

30 7 * * * root start -q anacron || : 30 17 * * * root /sbin/shutdown -h now

means that run 30 7 * * * root start -q anacron first, if that fails run 30 17 * * * root /sbin/shutdown -h now makes no sense i think. Just add the entry in crontab and that'll do the job.

heemayl
  • 91,753