djmaster329
Posts: 13
Joined: Thu Jun 28, 2012 3:18 pm

Automatic halt at certain time

Wed Nov 28, 2012 1:27 pm

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

User avatar
azeam
Posts: 194
Joined: Fri Oct 26, 2012 11:13 pm
Contact: Website

Re: Automatic halt at certain time

Wed Nov 28, 2012 2:40 pm

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

djmaster329
Posts: 13
Joined: Thu Jun 28, 2012 3:18 pm

Re: Automatic halt at certain time

Fri Nov 30, 2012 3:41 pm

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 ;)

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Automatic halt at certain time

Fri Nov 30, 2012 4:05 pm

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.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

djmaster329
Posts: 13
Joined: Thu Jun 28, 2012 3:18 pm

Re: Automatic halt at certain time

Fri Nov 30, 2012 5:47 pm

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

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Automatic halt at certain time

Fri Nov 30, 2012 6:55 pm

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.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Automatic halt at certain time

Fri Nov 30, 2012 7:16 pm

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
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
jojopi
Posts: 3271
Joined: Tue Oct 11, 2011 8:38 pm

Re: Automatic halt at certain time

Sat Dec 01, 2012 2:24 am

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

User avatar
azeam
Posts: 194
Joined: Fri Oct 26, 2012 11:13 pm
Contact: Website

Re: Automatic halt at certain time

Fri Dec 07, 2012 12:18 pm

Thanks for clarifying jojopi, I did it double up there ;)

Return to “Beginners”