ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Poweroff the raspberry after a specific time period!

Sun Oct 28, 2018 5:06 pm

Hi,
i want to poweroff my raspberry after a time period.
Example: after 6 hours since the poweron.
I know i can do this with the cron (crontab -e --> insert the right line) but in this way i need to set a specific time (in my case i cant' do this).
How can i do this?
Thanks a lot

Christian
Last edited by ducarpit on Sat Nov 10, 2018 7:43 am, edited 2 times in total.

DirkS
Posts: 9217
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Poweroff the raspberry after a specific time period!

Sun Oct 28, 2018 5:39 pm

See 'man shutdown'

This should work

Code: Select all

@reboot sudo /sbin/shutdown -p +3600
If you use the root crontab then you can leave out 'sudo'

User avatar
DougieLawson
Posts: 34096
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Poweroff the raspberry after a specific time period!

Sun Oct 28, 2018 5:56 pm

Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: Poweroff the raspberry after a specific time period!

Sun Oct 28, 2018 9:41 pm

DirkS wrote:
Sun Oct 28, 2018 5:39 pm
See 'man shutdown'

This should work

Code: Select all

@reboot sudo /sbin/shutdown -p +3600
If you use the root crontab then you can leave out 'sudo'

Hi, thanks a lot.
In the shutdown manual, there isn'it a -p (lower) parameter but only a -P that stands for "poweroff". Maybe you refer to -P (upper)....am i right?
The "+3600" stands for 3600 minutes as i can read in the manual...am i right?
Thanks a lot

DirkS
Posts: 9217
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Poweroff the raspberry after a specific time period!

Sun Oct 28, 2018 10:13 pm

ducarpit wrote:
Sun Oct 28, 2018 9:41 pm
In the shutdown manual, there isn'it a -p (lower) parameter but only a -P that stands for "poweroff". Maybe you refer to -P (upper)....am i right?
The "+3600" stands for 3600 minutes as i can read in the manual...am i right?
Thanks a lot
Correct on both counts. You can actually leave out the -P as it is the default.

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 10:56 am

Hi my dear,
thanks a lot.
I have tried your solution and it works!
But there is a problem: after the shutdown with the cron, i re-poweron my raspberry and i try to connect to him with SSH, but i got this:

Code: Select all

[email protected]:~$ ssh [email protected]
[email protected]'s password: 
System is going down.

Connection closed by 192.168.1.53 port 22
Maybe i can't connect with SSH while the "shutdown +10" is running.
What do you think?

Christian

User avatar
DougieLawson
Posts: 34096
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 11:05 am

You can connect as the root user. Regular users are blocked.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 12:10 pm

Perfect my friend....
Now, i have only to remove the broadcast message that say:

Code: Select all

Broadcast message from [email protected] (Mon 2018-10-29 13:07:36 CET):

The system is going down for poweroff at Mon 2018-10-29 13:14:36 CET!
But i think i just need to put the --no-wall parameter to the command.
Am i right?

Thank a lot

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 12:12 pm

Perfect my friend....
Now, i have only to remove the broadcast message that say:

Code: Select all

Broadcast message from [email protected] (Mon 2018-10-29 13:07:36 CET):

The system is going down for poweroff at Mon 2018-10-29 13:14:36 CET!
But i think i just need to put the --no-wall parameter to the command.
Am i right?

Thank a lot

epoch1970
Posts: 2075
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 3:33 pm

You can try it yourself.

Code: Select all

[email protected]:~ $ date; sudo shutdown -k +1; sleep 65; date
Mon Oct 29 16:28:29 CET 2018
Shutdown scheduled for Mon 2018-10-29 16:29:29 CET, use 'shutdown -c' to cancel.
Broadcast message from [email protected] (Mon 2018-10-29 16:28:29 CET):

The system is going down for power-off at Mon 2018-10-29 16:29:29 CET!


Mon Oct 29 16:29:34 CET 2018
[email protected]:~ $ 

Code: Select all

[email protected]:~ $ date; sudo shutdown -k --no-wall +1; sleep 65; date
Mon Oct 29 16:30:01 CET 2018
Shutdown scheduled for Mon 2018-10-29 16:31:01 CET, use 'shutdown -c' to cancel.
Mon Oct 29 16:31:06 CET 2018
[email protected]:~ $ 
shutdown option "-k" is used by admins to scare people off servers... It does not really execute shutdown.
Last edited by epoch1970 on Mon Oct 29, 2018 4:47 pm, edited 1 time in total.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: Poweroff the raspberry after a specific time period!

Mon Oct 29, 2018 4:18 pm

Perfect, many thankts to all my dear friends.....

ducarpit
Posts: 60
Joined: Mon Jan 09, 2017 8:32 am

Re: [Solved] Poweroff the raspberry after a specific time period!

Fri Nov 09, 2018 5:45 pm

Hi, i have a little problem: i inserted this line in the crontab file:

Code: Select all

@reboot /sbin/shutdown +420 --no-wall
and it works fine, after 420 minutes the Raspberry shutdowns without problems.
Unfortunatly, when i re-poweron it, it starts but after some seconds it poweroffs automatically.
I have to cut off the power and then re-poweron the Raspberry to start it.
Why?
Can someone help me?
Thanks

Christian

Return to “Raspbian”