How do I shut down a Linux server after running for 60 minutes?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
12
down vote

favorite
1












I have a server that it is normally switched off for security reasons. When I want to work on it I switch it on, execute my tasks, and shutdown it again. My tasks usually take 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?










share|improve this question









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.















  • 2




    Have a look at at (one-time execution).
    – dirkt
    yesterday






  • 8




    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
    yesterday










  • I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
    – sdkks
    yesterday






  • 7




    Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
    – Vicente Olivert Riera
    yesterday







  • 1




    Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
    – Patrick Taylor
    yesterday















up vote
12
down vote

favorite
1












I have a server that it is normally switched off for security reasons. When I want to work on it I switch it on, execute my tasks, and shutdown it again. My tasks usually take 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?










share|improve this question









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.















  • 2




    Have a look at at (one-time execution).
    – dirkt
    yesterday






  • 8




    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
    yesterday










  • I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
    – sdkks
    yesterday






  • 7




    Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
    – Vicente Olivert Riera
    yesterday







  • 1




    Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
    – Patrick Taylor
    yesterday













up vote
12
down vote

favorite
1









up vote
12
down vote

favorite
1






1





I have a server that it is normally switched off for security reasons. When I want to work on it I switch it on, execute my tasks, and shutdown it again. My tasks usually take 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?










share|improve this question









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 switch it on, execute my tasks, and shutdown it again. My tasks usually take 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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








edited 13 mins ago









Peter Mortensen

80558




80558






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 yesterday









jmhostalet

16615




16615




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.







  • 2




    Have a look at at (one-time execution).
    – dirkt
    yesterday






  • 8




    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
    yesterday










  • I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
    – sdkks
    yesterday






  • 7




    Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
    – Vicente Olivert Riera
    yesterday







  • 1




    Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
    – Patrick Taylor
    yesterday













  • 2




    Have a look at at (one-time execution).
    – dirkt
    yesterday






  • 8




    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
    yesterday










  • I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
    – sdkks
    yesterday






  • 7




    Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
    – Vicente Olivert Riera
    yesterday







  • 1




    Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
    – Patrick Taylor
    yesterday








2




2




Have a look at at (one-time execution).
– dirkt
yesterday




Have a look at at (one-time execution).
– dirkt
yesterday




8




8




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
yesterday




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
yesterday












I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
– sdkks
yesterday




I might have a solution that will shut it down as soon as your task is done. May I know how you run these tasks, by a bash script?
– sdkks
yesterday




7




7




Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
– Vicente Olivert Riera
yesterday





Depending on the nature of your tasks maybe it's worth running them inside a docker container, so you don't need to worry about switching off a server. The container is created, it runs your tasks, and it's destroyed after that.
– Vicente Olivert Riera
yesterday





1




1




Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
– Patrick Taylor
yesterday





Have you looked into uptime? You could have a periodic cron job that checks uptime and if the value is > 1hr then initiate init 0. You could also check ps -ef to see if your process is still running.
– Patrick Taylor
yesterday











8 Answers
8






active

oldest

votes

















up vote
14
down vote



accepted










If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of seconds the shutdown command is delayed.
Make sure your user has the ability to execute the shutdown command via sudo without a password.



echo "sudo shutdown -P 3600" >> ~/.profile





share|improve this answer


















  • 8




    The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
    – sebasth
    yesterday







  • 7




    But try the command one time first, you don't want an instant shutdown to be bound to your profile!
    – Fabian Röling
    yesterday






  • 10




    I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
    – JoL
    yesterday






  • 3




    It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
    – JoL
    yesterday






  • 1




    I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
    – undercat
    23 hours ago


















up vote
48
down vote













There are a several options.




  • Provide time directly to shutdown -P:



    shutdown -P 60


    Note that shutdown man page also points out:




    If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.




  • Use at command.


  • Create a systemd unit file or init script which runs shutdown -P 60 at startup.



  • Use cron's @reboot to run command after boot.



    Add to (root) crontab:



    @reboot shutdown -P 60


For the last two methods, you could also use sleep 3600 && shutdown -P instead of using time argument to shutdown to delay the shutdown for 60 minutes. This way logins are possible to the last moment before shutdown is issued.






share|improve this answer


















  • 1




    I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
    – Toby Speight
    17 hours ago

















up vote
16
down vote













This looks like an XY problem.




My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.




If you shut down after 60 minutes, you run the risk that you may be running a particularly complicated problem and just need to have more time. Many of the previous solutions would not make it easy to delay the shutdown.



If the task is not an interactive task, but instead are a scripted task that is automatically triggered from another machine, @sdkks gave a great solution for that; you really should just task the machine to run poweroff as soon as the script and all its tasks finishes.



However, if your task is an interactive task, I'd suggest to do idle detection instead.



If you do your task in a GUI (X11) you can detect the idle GUI sessions using the approach described here: Run a command when system is idle and when is active again



If you do the task through a terminal, you can detect logged in users using the who command. You can set up a cronjob that shuts the machine down if who returns an empty result. Note that this will be quite a conservative approach; it will not shut down the system if you left the console connected, but idle.



If you want to be a bit more aggressive and disconnect idle terminal sessions as well, you can combine the previous approach with automatically disconnecting idle SSH sessions ClientAliveInterval and ClientAliveCountMax. Another approach for this if you don't have SSH, but have a local terminal session, is to use the terminal idle time as returned by the w command.






share|improve this answer


















  • 1




    This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
    – Shadow
    yesterday

















up vote
6
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




share




















  • This task is right up at’s alley. You can also see at tasks in /var/spool/
    – sdkks
    yesterday






  • 3




    I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
    – Aaron
    yesterday










  • @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
    – sdkks
    yesterday

















up vote
4
down vote













Although previous answers here all satisfy the requirement to perfection, you can also make your machine power off as soon as the tasks are done.



bash scripts can be trapped, meaning certain signals can be intercepted and certain tasks can be executed when needed. EXIT is one of the signals that can be trapped.



You would be able to:



  1. Set a trap for EXIT of your automated shell scripts, meaning
    termination of your automated tasks

  2. Set a trap for your .bashrc EXIT, meaning whenever you log out
    of that machine, power it off.

Option #1 would be the ideal case, provided your tasks don't require adhoc inspection and manual judgement.



Option #2 would cover the cases where you'd forget to exit the terminal without powering off. There is a caveat though; if you have multiple terminals to the same machine open and you exit from one of them, it will still power off the machine all the same. (It can be scripted to avoid that, but I won't complicate the solution.)



cleanup()
# Do some tasks before terminating
echo oh la la, cleaning is so nice
echo "See you later, world"
sudo poweroff & # finally shutdown

trap cleanup EXIT


This can be at the end of .bashrc for option #2, at somewhere at the top of your script for option #1.



Why not use poweroff at the end of the script?



I prefer to use set -eo pipefail at on the top of my scripts. If any error happens, it won't silently fail; it will stop executing more commands. trap of EXIT signal should cover the cases where the script terminates prematurely due to errors.



However for your tasks, this might also mean the machine will shut down before they are completed.



I have a simple bash template I use for making scripting easier to debug; maybe it might be of some use. Please see this gist.






share|improve this answer






















  • If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
    – Abigail
    10 hours ago

















up vote
3
down vote













This runs command with params, and if it completes successfully will turn off the box immediately, assuming the user can run poweroff. May need to use sudo poweroff



command --parameters && poweroff



Whereas this one simply runs poweroff immediately when the command terminaltes



command --parameters ; poweroff



If you think the command needs rest time after completion, run



command --parameters ; sleep 3600 ; poweroff



If you think the command might run overtime you can constrain it to an hour



timeout 1h command --parameters ; poweroff


timeout is part of the coreutils package so you probably already have it.






share|improve this answer



























    up vote
    2
    down vote













    If you're really concerned about security, use an mechanical outlet timer on the power source. Just set it to whatever time you want it to shutdown. This way no one can login remotely and disable the shutdown. You would need physical access.






    share|improve this answer
















    • 1




      Filesystem corruption?
      – Xen2050
      yesterday










    • @Xen2050 not a problem on any modern (journaling) filesystem.
      – Tom
      20 hours ago










    • However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
      – Tom
      20 hours ago










    • @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
      – Xen2050
      20 hours ago






    • 1




      In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
      – Tom
      19 hours ago

















    up vote
    2
    down vote













    Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup.



    Or try using anacron, adding the command in the /etc/anacrontab file.
    I also suggest to use nohup in front of the command to be sure that the command is still working after logout.






    share|improve this answer










    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.

















    • Depending on distro, it might not get executed by just being in init.d
      – sdkks
      yesterday











    • @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
      – Saveriofr
      yesterday






    • 1




      @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
      – Anthony Geoghegan
      yesterday










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472718%2fhow-do-i-shut-down-a-linux-server-after-running-for-60-minutes%23new-answer', 'question_page');

    );

    Post as a guest






























    8 Answers
    8






    active

    oldest

    votes








    8 Answers
    8






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    14
    down vote



    accepted










    If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of seconds the shutdown command is delayed.
    Make sure your user has the ability to execute the shutdown command via sudo without a password.



    echo "sudo shutdown -P 3600" >> ~/.profile





    share|improve this answer


















    • 8




      The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
      – sebasth
      yesterday







    • 7




      But try the command one time first, you don't want an instant shutdown to be bound to your profile!
      – Fabian Röling
      yesterday






    • 10




      I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
      – JoL
      yesterday






    • 3




      It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
      – JoL
      yesterday






    • 1




      I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
      – undercat
      23 hours ago















    up vote
    14
    down vote



    accepted










    If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of seconds the shutdown command is delayed.
    Make sure your user has the ability to execute the shutdown command via sudo without a password.



    echo "sudo shutdown -P 3600" >> ~/.profile





    share|improve this answer


















    • 8




      The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
      – sebasth
      yesterday







    • 7




      But try the command one time first, you don't want an instant shutdown to be bound to your profile!
      – Fabian Röling
      yesterday






    • 10




      I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
      – JoL
      yesterday






    • 3




      It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
      – JoL
      yesterday






    • 1




      I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
      – undercat
      23 hours ago













    up vote
    14
    down vote



    accepted







    up vote
    14
    down vote



    accepted






    If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of seconds the shutdown command is delayed.
    Make sure your user has the ability to execute the shutdown command via sudo without a password.



    echo "sudo shutdown -P 3600" >> ~/.profile





    share|improve this answer














    If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of seconds the shutdown command is delayed.
    Make sure your user has the ability to execute the shutdown command via sudo without a password.



    echo "sudo shutdown -P 3600" >> ~/.profile






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 19 hours ago

























    answered yesterday









    Dirk Krijgsman

    3285




    3285







    • 8




      The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
      – sebasth
      yesterday







    • 7




      But try the command one time first, you don't want an instant shutdown to be bound to your profile!
      – Fabian Röling
      yesterday






    • 10




      I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
      – JoL
      yesterday






    • 3




      It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
      – JoL
      yesterday






    • 1




      I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
      – undercat
      23 hours ago













    • 8




      The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
      – sebasth
      yesterday







    • 7




      But try the command one time first, you don't want an instant shutdown to be bound to your profile!
      – Fabian Röling
      yesterday






    • 10




      I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
      – JoL
      yesterday






    • 3




      It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
      – JoL
      yesterday






    • 1




      I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
      – undercat
      23 hours ago








    8




    8




    The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
    – sebasth
    yesterday





    The time is in minutes, not seconds. Try shutdown -k -P 3600 vs shutdown -k -P 60 (-k prints wall message but doesn't have other effect)
    – sebasth
    yesterday





    7




    7




    But try the command one time first, you don't want an instant shutdown to be bound to your profile!
    – Fabian Röling
    yesterday




    But try the command one time first, you don't want an instant shutdown to be bound to your profile!
    – Fabian Röling
    yesterday




    10




    10




    I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
    – JoL
    yesterday




    I imagine every ssh login would cause a new call of shutdown. Would the counter reset then?
    – JoL
    yesterday




    3




    3




    It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
    – JoL
    yesterday




    It might also be worthwhile to mention that logins will not be allowed in the last 5 minutes, as mentioned in the shutdown manpage.
    – JoL
    yesterday




    1




    1




    I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
    – undercat
    23 hours ago





    I believe this solution will ask you for root password and start a new instance of shutdown every time a new login shell is launched which may or may not be a shortcoming.
    – undercat
    23 hours ago













    up vote
    48
    down vote













    There are a several options.




    • Provide time directly to shutdown -P:



      shutdown -P 60


      Note that shutdown man page also points out:




      If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.




    • Use at command.


    • Create a systemd unit file or init script which runs shutdown -P 60 at startup.



    • Use cron's @reboot to run command after boot.



      Add to (root) crontab:



      @reboot shutdown -P 60


    For the last two methods, you could also use sleep 3600 && shutdown -P instead of using time argument to shutdown to delay the shutdown for 60 minutes. This way logins are possible to the last moment before shutdown is issued.






    share|improve this answer


















    • 1




      I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
      – Toby Speight
      17 hours ago














    up vote
    48
    down vote













    There are a several options.




    • Provide time directly to shutdown -P:



      shutdown -P 60


      Note that shutdown man page also points out:




      If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.




    • Use at command.


    • Create a systemd unit file or init script which runs shutdown -P 60 at startup.



    • Use cron's @reboot to run command after boot.



      Add to (root) crontab:



      @reboot shutdown -P 60


    For the last two methods, you could also use sleep 3600 && shutdown -P instead of using time argument to shutdown to delay the shutdown for 60 minutes. This way logins are possible to the last moment before shutdown is issued.






    share|improve this answer


















    • 1




      I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
      – Toby Speight
      17 hours ago












    up vote
    48
    down vote










    up vote
    48
    down vote









    There are a several options.




    • Provide time directly to shutdown -P:



      shutdown -P 60


      Note that shutdown man page also points out:




      If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.




    • Use at command.


    • Create a systemd unit file or init script which runs shutdown -P 60 at startup.



    • Use cron's @reboot to run command after boot.



      Add to (root) crontab:



      @reboot shutdown -P 60


    For the last two methods, you could also use sleep 3600 && shutdown -P instead of using time argument to shutdown to delay the shutdown for 60 minutes. This way logins are possible to the last moment before shutdown is issued.






    share|improve this answer














    There are a several options.




    • Provide time directly to shutdown -P:



      shutdown -P 60


      Note that shutdown man page also points out:




      If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.




    • Use at command.


    • Create a systemd unit file or init script which runs shutdown -P 60 at startup.



    • Use cron's @reboot to run command after boot.



      Add to (root) crontab:



      @reboot shutdown -P 60


    For the last two methods, you could also use sleep 3600 && shutdown -P instead of using time argument to shutdown to delay the shutdown for 60 minutes. This way logins are possible to the last moment before shutdown is issued.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered yesterday









    sebasth

    7,00531745




    7,00531745







    • 1




      I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
      – Toby Speight
      17 hours ago












    • 1




      I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
      – Toby Speight
      17 hours ago







    1




    1




    I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
    – Toby Speight
    17 hours ago




    I think with the sleep command, you still need to specify a time to shutdown - we'd want to use now for that argument if we've already done the waiting (but note that you won't get very much warning to save your work before it disappears from under you!).
    – Toby Speight
    17 hours ago










    up vote
    16
    down vote













    This looks like an XY problem.




    My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.




    If you shut down after 60 minutes, you run the risk that you may be running a particularly complicated problem and just need to have more time. Many of the previous solutions would not make it easy to delay the shutdown.



    If the task is not an interactive task, but instead are a scripted task that is automatically triggered from another machine, @sdkks gave a great solution for that; you really should just task the machine to run poweroff as soon as the script and all its tasks finishes.



    However, if your task is an interactive task, I'd suggest to do idle detection instead.



    If you do your task in a GUI (X11) you can detect the idle GUI sessions using the approach described here: Run a command when system is idle and when is active again



    If you do the task through a terminal, you can detect logged in users using the who command. You can set up a cronjob that shuts the machine down if who returns an empty result. Note that this will be quite a conservative approach; it will not shut down the system if you left the console connected, but idle.



    If you want to be a bit more aggressive and disconnect idle terminal sessions as well, you can combine the previous approach with automatically disconnecting idle SSH sessions ClientAliveInterval and ClientAliveCountMax. Another approach for this if you don't have SSH, but have a local terminal session, is to use the terminal idle time as returned by the w command.






    share|improve this answer


















    • 1




      This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
      – Shadow
      yesterday














    up vote
    16
    down vote













    This looks like an XY problem.




    My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.




    If you shut down after 60 minutes, you run the risk that you may be running a particularly complicated problem and just need to have more time. Many of the previous solutions would not make it easy to delay the shutdown.



    If the task is not an interactive task, but instead are a scripted task that is automatically triggered from another machine, @sdkks gave a great solution for that; you really should just task the machine to run poweroff as soon as the script and all its tasks finishes.



    However, if your task is an interactive task, I'd suggest to do idle detection instead.



    If you do your task in a GUI (X11) you can detect the idle GUI sessions using the approach described here: Run a command when system is idle and when is active again



    If you do the task through a terminal, you can detect logged in users using the who command. You can set up a cronjob that shuts the machine down if who returns an empty result. Note that this will be quite a conservative approach; it will not shut down the system if you left the console connected, but idle.



    If you want to be a bit more aggressive and disconnect idle terminal sessions as well, you can combine the previous approach with automatically disconnecting idle SSH sessions ClientAliveInterval and ClientAliveCountMax. Another approach for this if you don't have SSH, but have a local terminal session, is to use the terminal idle time as returned by the w command.






    share|improve this answer


















    • 1




      This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
      – Shadow
      yesterday












    up vote
    16
    down vote










    up vote
    16
    down vote









    This looks like an XY problem.




    My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.




    If you shut down after 60 minutes, you run the risk that you may be running a particularly complicated problem and just need to have more time. Many of the previous solutions would not make it easy to delay the shutdown.



    If the task is not an interactive task, but instead are a scripted task that is automatically triggered from another machine, @sdkks gave a great solution for that; you really should just task the machine to run poweroff as soon as the script and all its tasks finishes.



    However, if your task is an interactive task, I'd suggest to do idle detection instead.



    If you do your task in a GUI (X11) you can detect the idle GUI sessions using the approach described here: Run a command when system is idle and when is active again



    If you do the task through a terminal, you can detect logged in users using the who command. You can set up a cronjob that shuts the machine down if who returns an empty result. Note that this will be quite a conservative approach; it will not shut down the system if you left the console connected, but idle.



    If you want to be a bit more aggressive and disconnect idle terminal sessions as well, you can combine the previous approach with automatically disconnecting idle SSH sessions ClientAliveInterval and ClientAliveCountMax. Another approach for this if you don't have SSH, but have a local terminal session, is to use the terminal idle time as returned by the w command.






    share|improve this answer














    This looks like an XY problem.




    My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes.




    If you shut down after 60 minutes, you run the risk that you may be running a particularly complicated problem and just need to have more time. Many of the previous solutions would not make it easy to delay the shutdown.



    If the task is not an interactive task, but instead are a scripted task that is automatically triggered from another machine, @sdkks gave a great solution for that; you really should just task the machine to run poweroff as soon as the script and all its tasks finishes.



    However, if your task is an interactive task, I'd suggest to do idle detection instead.



    If you do your task in a GUI (X11) you can detect the idle GUI sessions using the approach described here: Run a command when system is idle and when is active again



    If you do the task through a terminal, you can detect logged in users using the who command. You can set up a cronjob that shuts the machine down if who returns an empty result. Note that this will be quite a conservative approach; it will not shut down the system if you left the console connected, but idle.



    If you want to be a bit more aggressive and disconnect idle terminal sessions as well, you can combine the previous approach with automatically disconnecting idle SSH sessions ClientAliveInterval and ClientAliveCountMax. Another approach for this if you don't have SSH, but have a local terminal session, is to use the terminal idle time as returned by the w command.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 12 mins ago









    Peter Mortensen

    80558




    80558










    answered yesterday









    Lie Ryan

    78338




    78338







    • 1




      This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
      – Shadow
      yesterday












    • 1




      This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
      – Shadow
      yesterday







    1




    1




    This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
    – Shadow
    yesterday




    This is a very important point. Whatever you implement - it's in your interest to make sure that you can also cancel the shut down.
    – Shadow
    yesterday










    up vote
    6
    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




    share




















    • This task is right up at’s alley. You can also see at tasks in /var/spool/
      – sdkks
      yesterday






    • 3




      I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
      – Aaron
      yesterday










    • @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
      – sdkks
      yesterday














    up vote
    6
    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




    share




















    • This task is right up at’s alley. You can also see at tasks in /var/spool/
      – sdkks
      yesterday






    • 3




      I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
      – Aaron
      yesterday










    • @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
      – sdkks
      yesterday












    up vote
    6
    down vote










    up vote
    6
    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




    share












    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





    share











    share


    share










    answered yesterday









    Mr Shunz

    2,77111720




    2,77111720











    • This task is right up at’s alley. You can also see at tasks in /var/spool/
      – sdkks
      yesterday






    • 3




      I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
      – Aaron
      yesterday










    • @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
      – sdkks
      yesterday
















    • This task is right up at’s alley. You can also see at tasks in /var/spool/
      – sdkks
      yesterday






    • 3




      I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
      – Aaron
      yesterday










    • @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
      – sdkks
      yesterday















    This task is right up at’s alley. You can also see at tasks in /var/spool/
    – sdkks
    yesterday




    This task is right up at’s alley. You can also see at tasks in /var/spool/
    – sdkks
    yesterday




    3




    3




    I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
    – Aaron
    yesterday




    I would advice against using at in this context because it survives reboots. If OP were to log in, manually shutdown and then log in again in the span of an hour, he'd get kicked off before an hour passed after his last login when the first scheduled shutdown proc.
    – Aaron
    yesterday












    @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
    – sdkks
    yesterday




    @Aaron that’s true. Haven’t thought of that. Boot persistence is a caveat for this solution.
    – sdkks
    yesterday










    up vote
    4
    down vote













    Although previous answers here all satisfy the requirement to perfection, you can also make your machine power off as soon as the tasks are done.



    bash scripts can be trapped, meaning certain signals can be intercepted and certain tasks can be executed when needed. EXIT is one of the signals that can be trapped.



    You would be able to:



    1. Set a trap for EXIT of your automated shell scripts, meaning
      termination of your automated tasks

    2. Set a trap for your .bashrc EXIT, meaning whenever you log out
      of that machine, power it off.

    Option #1 would be the ideal case, provided your tasks don't require adhoc inspection and manual judgement.



    Option #2 would cover the cases where you'd forget to exit the terminal without powering off. There is a caveat though; if you have multiple terminals to the same machine open and you exit from one of them, it will still power off the machine all the same. (It can be scripted to avoid that, but I won't complicate the solution.)



    cleanup()
    # Do some tasks before terminating
    echo oh la la, cleaning is so nice
    echo "See you later, world"
    sudo poweroff & # finally shutdown

    trap cleanup EXIT


    This can be at the end of .bashrc for option #2, at somewhere at the top of your script for option #1.



    Why not use poweroff at the end of the script?



    I prefer to use set -eo pipefail at on the top of my scripts. If any error happens, it won't silently fail; it will stop executing more commands. trap of EXIT signal should cover the cases where the script terminates prematurely due to errors.



    However for your tasks, this might also mean the machine will shut down before they are completed.



    I have a simple bash template I use for making scripting easier to debug; maybe it might be of some use. Please see this gist.






    share|improve this answer






















    • If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
      – Abigail
      10 hours ago














    up vote
    4
    down vote













    Although previous answers here all satisfy the requirement to perfection, you can also make your machine power off as soon as the tasks are done.



    bash scripts can be trapped, meaning certain signals can be intercepted and certain tasks can be executed when needed. EXIT is one of the signals that can be trapped.



    You would be able to:



    1. Set a trap for EXIT of your automated shell scripts, meaning
      termination of your automated tasks

    2. Set a trap for your .bashrc EXIT, meaning whenever you log out
      of that machine, power it off.

    Option #1 would be the ideal case, provided your tasks don't require adhoc inspection and manual judgement.



    Option #2 would cover the cases where you'd forget to exit the terminal without powering off. There is a caveat though; if you have multiple terminals to the same machine open and you exit from one of them, it will still power off the machine all the same. (It can be scripted to avoid that, but I won't complicate the solution.)



    cleanup()
    # Do some tasks before terminating
    echo oh la la, cleaning is so nice
    echo "See you later, world"
    sudo poweroff & # finally shutdown

    trap cleanup EXIT


    This can be at the end of .bashrc for option #2, at somewhere at the top of your script for option #1.



    Why not use poweroff at the end of the script?



    I prefer to use set -eo pipefail at on the top of my scripts. If any error happens, it won't silently fail; it will stop executing more commands. trap of EXIT signal should cover the cases where the script terminates prematurely due to errors.



    However for your tasks, this might also mean the machine will shut down before they are completed.



    I have a simple bash template I use for making scripting easier to debug; maybe it might be of some use. Please see this gist.






    share|improve this answer






















    • If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
      – Abigail
      10 hours ago












    up vote
    4
    down vote










    up vote
    4
    down vote









    Although previous answers here all satisfy the requirement to perfection, you can also make your machine power off as soon as the tasks are done.



    bash scripts can be trapped, meaning certain signals can be intercepted and certain tasks can be executed when needed. EXIT is one of the signals that can be trapped.



    You would be able to:



    1. Set a trap for EXIT of your automated shell scripts, meaning
      termination of your automated tasks

    2. Set a trap for your .bashrc EXIT, meaning whenever you log out
      of that machine, power it off.

    Option #1 would be the ideal case, provided your tasks don't require adhoc inspection and manual judgement.



    Option #2 would cover the cases where you'd forget to exit the terminal without powering off. There is a caveat though; if you have multiple terminals to the same machine open and you exit from one of them, it will still power off the machine all the same. (It can be scripted to avoid that, but I won't complicate the solution.)



    cleanup()
    # Do some tasks before terminating
    echo oh la la, cleaning is so nice
    echo "See you later, world"
    sudo poweroff & # finally shutdown

    trap cleanup EXIT


    This can be at the end of .bashrc for option #2, at somewhere at the top of your script for option #1.



    Why not use poweroff at the end of the script?



    I prefer to use set -eo pipefail at on the top of my scripts. If any error happens, it won't silently fail; it will stop executing more commands. trap of EXIT signal should cover the cases where the script terminates prematurely due to errors.



    However for your tasks, this might also mean the machine will shut down before they are completed.



    I have a simple bash template I use for making scripting easier to debug; maybe it might be of some use. Please see this gist.






    share|improve this answer














    Although previous answers here all satisfy the requirement to perfection, you can also make your machine power off as soon as the tasks are done.



    bash scripts can be trapped, meaning certain signals can be intercepted and certain tasks can be executed when needed. EXIT is one of the signals that can be trapped.



    You would be able to:



    1. Set a trap for EXIT of your automated shell scripts, meaning
      termination of your automated tasks

    2. Set a trap for your .bashrc EXIT, meaning whenever you log out
      of that machine, power it off.

    Option #1 would be the ideal case, provided your tasks don't require adhoc inspection and manual judgement.



    Option #2 would cover the cases where you'd forget to exit the terminal without powering off. There is a caveat though; if you have multiple terminals to the same machine open and you exit from one of them, it will still power off the machine all the same. (It can be scripted to avoid that, but I won't complicate the solution.)



    cleanup()
    # Do some tasks before terminating
    echo oh la la, cleaning is so nice
    echo "See you later, world"
    sudo poweroff & # finally shutdown

    trap cleanup EXIT


    This can be at the end of .bashrc for option #2, at somewhere at the top of your script for option #1.



    Why not use poweroff at the end of the script?



    I prefer to use set -eo pipefail at on the top of my scripts. If any error happens, it won't silently fail; it will stop executing more commands. trap of EXIT signal should cover the cases where the script terminates prematurely due to errors.



    However for your tasks, this might also mean the machine will shut down before they are completed.



    I have a simple bash template I use for making scripting easier to debug; maybe it might be of some use. Please see this gist.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 12 mins ago









    Peter Mortensen

    80558




    80558










    answered yesterday









    sdkks

    1936




    1936











    • If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
      – Abigail
      10 hours ago
















    • If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
      – Abigail
      10 hours ago















    If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
    – Abigail
    10 hours ago




    If you do it at the end of the script, your machine won't be shutdown if for whatever reason, the script isn't started.
    – Abigail
    10 hours ago










    up vote
    3
    down vote













    This runs command with params, and if it completes successfully will turn off the box immediately, assuming the user can run poweroff. May need to use sudo poweroff



    command --parameters && poweroff



    Whereas this one simply runs poweroff immediately when the command terminaltes



    command --parameters ; poweroff



    If you think the command needs rest time after completion, run



    command --parameters ; sleep 3600 ; poweroff



    If you think the command might run overtime you can constrain it to an hour



    timeout 1h command --parameters ; poweroff


    timeout is part of the coreutils package so you probably already have it.






    share|improve this answer
























      up vote
      3
      down vote













      This runs command with params, and if it completes successfully will turn off the box immediately, assuming the user can run poweroff. May need to use sudo poweroff



      command --parameters && poweroff



      Whereas this one simply runs poweroff immediately when the command terminaltes



      command --parameters ; poweroff



      If you think the command needs rest time after completion, run



      command --parameters ; sleep 3600 ; poweroff



      If you think the command might run overtime you can constrain it to an hour



      timeout 1h command --parameters ; poweroff


      timeout is part of the coreutils package so you probably already have it.






      share|improve this answer






















        up vote
        3
        down vote










        up vote
        3
        down vote









        This runs command with params, and if it completes successfully will turn off the box immediately, assuming the user can run poweroff. May need to use sudo poweroff



        command --parameters && poweroff



        Whereas this one simply runs poweroff immediately when the command terminaltes



        command --parameters ; poweroff



        If you think the command needs rest time after completion, run



        command --parameters ; sleep 3600 ; poweroff



        If you think the command might run overtime you can constrain it to an hour



        timeout 1h command --parameters ; poweroff


        timeout is part of the coreutils package so you probably already have it.






        share|improve this answer












        This runs command with params, and if it completes successfully will turn off the box immediately, assuming the user can run poweroff. May need to use sudo poweroff



        command --parameters && poweroff



        Whereas this one simply runs poweroff immediately when the command terminaltes



        command --parameters ; poweroff



        If you think the command needs rest time after completion, run



        command --parameters ; sleep 3600 ; poweroff



        If you think the command might run overtime you can constrain it to an hour



        timeout 1h command --parameters ; poweroff


        timeout is part of the coreutils package so you probably already have it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Criggie

        739410




        739410




















            up vote
            2
            down vote













            If you're really concerned about security, use an mechanical outlet timer on the power source. Just set it to whatever time you want it to shutdown. This way no one can login remotely and disable the shutdown. You would need physical access.






            share|improve this answer
















            • 1




              Filesystem corruption?
              – Xen2050
              yesterday










            • @Xen2050 not a problem on any modern (journaling) filesystem.
              – Tom
              20 hours ago










            • However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
              – Tom
              20 hours ago










            • @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
              – Xen2050
              20 hours ago






            • 1




              In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
              – Tom
              19 hours ago














            up vote
            2
            down vote













            If you're really concerned about security, use an mechanical outlet timer on the power source. Just set it to whatever time you want it to shutdown. This way no one can login remotely and disable the shutdown. You would need physical access.






            share|improve this answer
















            • 1




              Filesystem corruption?
              – Xen2050
              yesterday










            • @Xen2050 not a problem on any modern (journaling) filesystem.
              – Tom
              20 hours ago










            • However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
              – Tom
              20 hours ago










            • @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
              – Xen2050
              20 hours ago






            • 1




              In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
              – Tom
              19 hours ago












            up vote
            2
            down vote










            up vote
            2
            down vote









            If you're really concerned about security, use an mechanical outlet timer on the power source. Just set it to whatever time you want it to shutdown. This way no one can login remotely and disable the shutdown. You would need physical access.






            share|improve this answer












            If you're really concerned about security, use an mechanical outlet timer on the power source. Just set it to whatever time you want it to shutdown. This way no one can login remotely and disable the shutdown. You would need physical access.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            gogators

            2771210




            2771210







            • 1




              Filesystem corruption?
              – Xen2050
              yesterday










            • @Xen2050 not a problem on any modern (journaling) filesystem.
              – Tom
              20 hours ago










            • However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
              – Tom
              20 hours ago










            • @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
              – Xen2050
              20 hours ago






            • 1




              In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
              – Tom
              19 hours ago












            • 1




              Filesystem corruption?
              – Xen2050
              yesterday










            • @Xen2050 not a problem on any modern (journaling) filesystem.
              – Tom
              20 hours ago










            • However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
              – Tom
              20 hours ago










            • @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
              – Xen2050
              20 hours ago






            • 1




              In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
              – Tom
              19 hours ago







            1




            1




            Filesystem corruption?
            – Xen2050
            yesterday




            Filesystem corruption?
            – Xen2050
            yesterday












            @Xen2050 not a problem on any modern (journaling) filesystem.
            – Tom
            20 hours ago




            @Xen2050 not a problem on any modern (journaling) filesystem.
            – Tom
            20 hours ago












            However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
            – Tom
            20 hours ago




            However, a better solution would indeed be to have poweroff system that can send proper SNMP signals for a clean shutdown.
            – Tom
            20 hours ago












            @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
            – Xen2050
            20 hours ago




            @Tom Do you have a source for forced umounts will never cause filesystem corruption if there's journaling? Sounds new to me, I'd like to read up on it. At the very least it must mark the filesystem as dirty, forcing a fsck right?
            – Xen2050
            20 hours ago




            1




            1




            In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
            – Tom
            19 hours ago




            In most cases, it should just replay the journal and be done with it. A powerdown should not cause filesystem corruption on a journaled filesystem, though there are no guarantees unless you use a filesystem such as ZFS which is specifically designed for this case.
            – Tom
            19 hours ago










            up vote
            2
            down vote













            Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup.



            Or try using anacron, adding the command in the /etc/anacrontab file.
            I also suggest to use nohup in front of the command to be sure that the command is still working after logout.






            share|improve this answer










            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.

















            • Depending on distro, it might not get executed by just being in init.d
              – sdkks
              yesterday











            • @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
              – Saveriofr
              yesterday






            • 1




              @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
              – Anthony Geoghegan
              yesterday














            up vote
            2
            down vote













            Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup.



            Or try using anacron, adding the command in the /etc/anacrontab file.
            I also suggest to use nohup in front of the command to be sure that the command is still working after logout.






            share|improve this answer










            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.

















            • Depending on distro, it might not get executed by just being in init.d
              – sdkks
              yesterday











            • @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
              – Saveriofr
              yesterday






            • 1




              @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
              – Anthony Geoghegan
              yesterday












            up vote
            2
            down vote










            up vote
            2
            down vote









            Try to put the script (sudo shutdown -P 3600) in the /etc/init.d directory to run it automatically at startup.



            Or try using anacron, adding the command in the /etc/anacrontab file.
            I also suggest to use nohup in front of the command to be sure that the command is still working after logout.






            share|improve this answer










            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.



            Or try using anacron, adding the command in the /etc/anacrontab file.
            I also suggest to use nohup in front of the command to be sure that the command is still working after logout.







            share|improve this answer










            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.









            share|improve this answer



            share|improve this answer








            edited 38 mins ago









            Peter Mortensen

            80558




            80558






            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 yesterday









            Saveriofr

            173




            173




            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.











            • Depending on distro, it might not get executed by just being in init.d
              – sdkks
              yesterday











            • @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
              – Saveriofr
              yesterday






            • 1




              @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
              – Anthony Geoghegan
              yesterday
















            • Depending on distro, it might not get executed by just being in init.d
              – sdkks
              yesterday











            • @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
              – Saveriofr
              yesterday






            • 1




              @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
              – Anthony Geoghegan
              yesterday















            Depending on distro, it might not get executed by just being in init.d
            – sdkks
            yesterday





            Depending on distro, it might not get executed by just being in init.d
            – sdkks
            yesterday













            @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
            – Saveriofr
            yesterday




            @sdkks, you're right. Anacron can be also considered. putting the script in /etc/anacrontab, also used with 'nohup' in the event of logout.
            – Saveriofr
            yesterday




            1




            1




            @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
            – Anthony Geoghegan
            yesterday




            @Saveriofr You can edit your answer to improve its quality (better than posting additional info as a comment).
            – Anthony Geoghegan
            yesterday










            jmhostalet is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            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.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472718%2fhow-do-i-shut-down-a-linux-server-after-running-for-60-minutes%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery