How to shut down linux server after 60 minutes running

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










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.















  • 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 could sudo shutdown -c (this doesn't use cron though)
    – guiverc
    33 mins ago














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?










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.















  • 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 could sudo shutdown -c (this doesn't use cron though)
    – guiverc
    33 mins ago












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?










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






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 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 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 could sudo shutdown -c (this doesn't use cron though)
    – guiverc
    33 mins ago












  • 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 could sudo 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










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





share|improve this answer



























    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.






    share|improve this answer






















    • +1 for the crons reboot, I was answering that too.
      – Rui F Ribeiro
      25 mins ago

















    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





    share|improve this answer




















    • thanks for welcome me
      – jmhostalet
      18 mins ago

















    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





    share








    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.

















      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-to-shut-down-linux-server-after-60-minutes-running%23new-answer', 'question_page');

      );

      Post as a guest






























      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





      share|improve this answer
























        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





        share|improve this answer






















          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





          share|improve this answer












          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 32 mins ago









          Dirk Krijgsman

          712




          712






















              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.






              share|improve this answer






















              • +1 for the crons reboot, I was answering that too.
                – Rui F Ribeiro
                25 mins ago














              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.






              share|improve this answer






















              • +1 for the crons reboot, I was answering that too.
                – Rui F Ribeiro
                25 mins ago












              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.






              share|improve this answer














              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.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              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
















              • +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










              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





              share|improve this answer




















              • thanks for welcome me
                – jmhostalet
                18 mins ago














              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





              share|improve this answer




















              • thanks for welcome me
                – jmhostalet
                18 mins ago












              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





              share|improve this answer












              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|improve this answer












              share|improve this answer



              share|improve this answer










              answered 33 mins ago









              Mr Shunz

              2,66811720




              2,66811720











              • thanks for welcome me
                – jmhostalet
                18 mins ago
















              • thanks for welcome me
                – jmhostalet
                18 mins ago















              thanks for welcome me
              – jmhostalet
              18 mins ago




              thanks for welcome me
              – jmhostalet
              18 mins ago










              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





              share








              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.





















                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





                share








                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.



















                  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





                  share








                  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






                  share








                  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


                  share






                  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.




















                      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-to-shut-down-linux-server-after-60-minutes-running%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery