How to shut down linux server after 60 minutes running
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a server that it is normally switched off for security reasons. When I want to work on it I swith it on, execute my tasks and I shutdown it again. My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.
I've researched how to do this with cron, but I don't think it's the proper way because cron doesn't take into account when the server was last turned on, I can only set periodic patterns but they don't take that data into account.
How could I do this implementation?
linux cron date shutdown
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
I have a server that it is normally switched off for security reasons. When I want to work on it I swith it on, execute my tasks and I shutdown it again. My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.
I've researched how to do this with cron, but I don't think it's the proper way because cron doesn't take into account when the server was last turned on, I can only set periodic patterns but they don't take that data into account.
How could I do this implementation?
linux cron date shutdown
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Have a look atat
(one-time execution).
– dirkt
38 mins ago
1
I haven't done this, but your login script could start asudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you couldsudo shutdown -c
(this doesn't use cron though)
– guiverc
33 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a server that it is normally switched off for security reasons. When I want to work on it I swith it on, execute my tasks and I shutdown it again. My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.
I've researched how to do this with cron, but I don't think it's the proper way because cron doesn't take into account when the server was last turned on, I can only set periodic patterns but they don't take that data into account.
How could I do this implementation?
linux cron date shutdown
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a server that it is normally switched off for security reasons. When I want to work on it I swith it on, execute my tasks and I shutdown it again. My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.
I've researched how to do this with cron, but I don't think it's the proper way because cron doesn't take into account when the server was last turned on, I can only set periodic patterns but they don't take that data into account.
How could I do this implementation?
linux cron date shutdown
linux cron date shutdown
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 17 mins ago


Jeff Schaller
33.1k849111
33.1k849111
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 42 mins ago
jmhostalet
1113
1113
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
jmhostalet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Have a look atat
(one-time execution).
– dirkt
38 mins ago
1
I haven't done this, but your login script could start asudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you couldsudo shutdown -c
(this doesn't use cron though)
– guiverc
33 mins ago
add a comment |Â
1
Have a look atat
(one-time execution).
– dirkt
38 mins ago
1
I haven't done this, but your login script could start asudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you couldsudo shutdown -c
(this doesn't use cron though)
– guiverc
33 mins ago
1
1
Have a look at
at
(one-time execution).– dirkt
38 mins ago
Have a look at
at
(one-time execution).– dirkt
38 mins ago
1
1
I haven't done this, but your login script could start a
sudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you could sudo shutdown -c
(this doesn't use cron though)– guiverc
33 mins ago
I haven't done this, but your login script could start a
sudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you could sudo shutdown -c
(this doesn't use cron though)– guiverc
33 mins ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
3
down vote
accepted
If you execute your tasks as the same user every time, you can simply add the shutdown command with the option -P to your profile. The number stands for the amount of seconds the shutdown command is delayed.
echo "sudo shutdown -P 3600" >> ~/.profile
add a comment |Â
up vote
4
down vote
There are a couple of options:
Provide time directly to
poweroff
as argument:poweroff 60
Create a systemd service/init script which runs poweroff.
Use cron's
@reboot
, to runs command after boot:Add to (root) crontab:
@reboot sleep 3600 && poweroff
Use
at
command.
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
add a comment |Â
up vote
1
down vote
Hello and welcome to this site!
Elaborating on @dirkt comment, you can insert an at
command on your .bashrc
or .profile
or whichever file your shell uses on login to schedule an automatic shutdown 60 minutes after your login.
Something like:
at now + 60 minutes -f /sbin/halt
thanks for welcome me
– jmhostalet
18 mins ago
add a comment |Â
up vote
0
down vote
Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
If you execute your tasks as the same user every time, you can simply add the shutdown command with the option -P to your profile. The number stands for the amount of seconds the shutdown command is delayed.
echo "sudo shutdown -P 3600" >> ~/.profile
add a comment |Â
up vote
3
down vote
accepted
If you execute your tasks as the same user every time, you can simply add the shutdown command with the option -P to your profile. The number stands for the amount of seconds the shutdown command is delayed.
echo "sudo shutdown -P 3600" >> ~/.profile
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
If you execute your tasks as the same user every time, you can simply add the shutdown command with the option -P to your profile. The number stands for the amount of seconds the shutdown command is delayed.
echo "sudo shutdown -P 3600" >> ~/.profile
If you execute your tasks as the same user every time, you can simply add the shutdown command with the option -P to your profile. The number stands for the amount of seconds the shutdown command is delayed.
echo "sudo shutdown -P 3600" >> ~/.profile
answered 32 mins ago
Dirk Krijgsman
712
712
add a comment |Â
add a comment |Â
up vote
4
down vote
There are a couple of options:
Provide time directly to
poweroff
as argument:poweroff 60
Create a systemd service/init script which runs poweroff.
Use cron's
@reboot
, to runs command after boot:Add to (root) crontab:
@reboot sleep 3600 && poweroff
Use
at
command.
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
add a comment |Â
up vote
4
down vote
There are a couple of options:
Provide time directly to
poweroff
as argument:poweroff 60
Create a systemd service/init script which runs poweroff.
Use cron's
@reboot
, to runs command after boot:Add to (root) crontab:
@reboot sleep 3600 && poweroff
Use
at
command.
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
There are a couple of options:
Provide time directly to
poweroff
as argument:poweroff 60
Create a systemd service/init script which runs poweroff.
Use cron's
@reboot
, to runs command after boot:Add to (root) crontab:
@reboot sleep 3600 && poweroff
Use
at
command.
There are a couple of options:
Provide time directly to
poweroff
as argument:poweroff 60
Create a systemd service/init script which runs poweroff.
Use cron's
@reboot
, to runs command after boot:Add to (root) crontab:
@reboot sleep 3600 && poweroff
Use
at
command.
edited 27 mins ago
answered 33 mins ago


sebasth
6,64121644
6,64121644
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
add a comment |Â
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
+1 for the crons reboot, I was answering that too.
– Rui F Ribeiro
25 mins ago
add a comment |Â
up vote
1
down vote
Hello and welcome to this site!
Elaborating on @dirkt comment, you can insert an at
command on your .bashrc
or .profile
or whichever file your shell uses on login to schedule an automatic shutdown 60 minutes after your login.
Something like:
at now + 60 minutes -f /sbin/halt
thanks for welcome me
– jmhostalet
18 mins ago
add a comment |Â
up vote
1
down vote
Hello and welcome to this site!
Elaborating on @dirkt comment, you can insert an at
command on your .bashrc
or .profile
or whichever file your shell uses on login to schedule an automatic shutdown 60 minutes after your login.
Something like:
at now + 60 minutes -f /sbin/halt
thanks for welcome me
– jmhostalet
18 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Hello and welcome to this site!
Elaborating on @dirkt comment, you can insert an at
command on your .bashrc
or .profile
or whichever file your shell uses on login to schedule an automatic shutdown 60 minutes after your login.
Something like:
at now + 60 minutes -f /sbin/halt
Hello and welcome to this site!
Elaborating on @dirkt comment, you can insert an at
command on your .bashrc
or .profile
or whichever file your shell uses on login to schedule an automatic shutdown 60 minutes after your login.
Something like:
at now + 60 minutes -f /sbin/halt
answered 33 mins ago
Mr Shunz
2,66811720
2,66811720
thanks for welcome me
– jmhostalet
18 mins ago
add a comment |Â
thanks for welcome me
– jmhostalet
18 mins ago
thanks for welcome me
– jmhostalet
18 mins ago
thanks for welcome me
– jmhostalet
18 mins ago
add a comment |Â
up vote
0
down vote
Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 7 mins ago


Saveriofr
62
62
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Saveriofr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.
jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.
jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.
jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472718%2fhow-to-shut-down-linux-server-after-60-minutes-running%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Have a look at
at
(one-time execution).– dirkt
38 mins ago
1
I haven't done this, but your login script could start a
sudo shutdown -h +60
which would start a countdown counter of 60 mins for the shutdown (-halt) process. If you wanted to cancel it, you couldsudo shutdown -c
(this doesn't use cron though)– guiverc
33 mins ago