Page 1 of 1

Automatic halt at certain time

Posted: Wed Nov 28, 2012 1:27 pm
by djmaster329
Hello,

I have a quick and simple question:
How do I make my Pi shutdown every day at the same time? I have already tried a few things, but is does not seem to work :S

Re: Automatic halt at certain time

Posted: Wed Nov 28, 2012 2:40 pm
by azeam

Code: Select all

sudo crontab -e
and add on a new line at the end (0 0 = shuts down at midnight every day, see https://wiki.archlinux.org/index.php/Cron#Examples for more examples)

Code: Select all

0 0 * * * root /sbin/shutdown -h now

Re: Automatic halt at certain time

Posted: Fri Nov 30, 2012 3:41 pm
by djmaster329
Hi,

I added the following line to my crontab:

Code: Select all

0 21 * * * root /sbin/shutdown -h now
But it does not shut down at 21:00 (9P.M.).

I tested it two days in a row, that's why it took so long for me to reply ;)

Re: Automatic halt at certain time

Posted: Fri Nov 30, 2012 4:05 pm
by pluggy
It works for me on latest Raspdian, not waiting for 21:00 just a minute or two ahead of the present time.

Code: Select all

52 15 * * * root halt
52 15 * * * root shutdown -h now
52 15 * * * root /sbin/shutdown -h now
all work.

Obviously it only halts the operating system, the Pi is still powered on afterwards. It would need some proper power management in the equation to actually turn it off.

Re: Automatic halt at certain time

Posted: Fri Nov 30, 2012 5:47 pm
by djmaster329
pluggy wrote:It works for me on latest Raspdian, not waiting for 21:00 just a minute or two ahead of the present time.

Code: Select all

52 15 * * * root halt
52 15 * * * root shutdown -h now
52 15 * * * root /sbin/shutdown -h now
So if I'd replace the current line with:

Code: Select all

02 21 * * * root halt
02 21 * * * root shutdown -h now
02 21 * * * root /sbin/shutdown -h now
it should work?
pluggy wrote:Obviously it only halts the operating system, the Pi is still powered on afterwards. It would need some proper power management in the equation to actually turn it off.
I know, but I was able to connect to the SSH server, so it did not halt at all :P

Re: Automatic halt at certain time

Posted: Fri Nov 30, 2012 6:55 pm
by pluggy
No you just need one of them. I tried them all on my Pi individually, they all work which isn't surprising since they are basically the same thing. There's something wrong at your end.

How exactly did you add you add the line to the /etc/crontab file ?

I edited mine using gedit on my Ubuntu box saving them back via SSH.

Re: Automatic halt at certain time

Posted: Fri Nov 30, 2012 7:16 pm
by pluggy
Ah, if you followed the advice of the earlier poster and went down the sudo crontab -e route, it doesn't work using the default path for the file. I've been doing it the way I always do it by directly editting the /etc/crontab file.

It does work by doing it this way :

Code: Select all

sudo nano /etc/crontab

Re: Automatic halt at certain time

Posted: Sat Dec 01, 2012 2:24 am
by jojopi
If you edit /etc/crontab or /etc/cron.d/* you must include the user name to run the command as as the sixth field:

Code: Select all

2 21 * * * root /sbin/shutdown -h now
If you use "sudo crontab -e" this edits /var/spool/cron/crontabs/root so the user is implied and must not be specifed:

Code: Select all

2 21 * * * /sbin/shutdown -h now

Re: Automatic halt at certain time

Posted: Fri Dec 07, 2012 12:18 pm
by azeam
Thanks for clarifying jojopi, I did it double up there ;)