upstart run script between particular time












1















I would like to run a script between two hours using upstart:




  • start at: 9h00

  • stop at: 23h30


This is my upstart:



author "bakka"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

script
H_BEGIN="905"
H_END="2330"
H_NOW=$(date +%k%M)

if [[ ${H_NOW} -gt ${H_BEGIN} && ${H_NOW} -lt ${H_END} ]]; then
exec my_python_script
fi
end script


but it doesn't seems to take the condition, even if i remove the "start on runlevel [2345]"



i've already take a look here: http://upstart.ubuntu.com/faq.html#replace-cron




You'd be able to have a service only running between particular times,
or on particular days, etc.
Blockquote




But it's not made very clear.



If somebody knows how to specify a between time to launch something by using upstart, it would be nice.










share|improve this question



























    1















    I would like to run a script between two hours using upstart:




    • start at: 9h00

    • stop at: 23h30


    This is my upstart:



    author "bakka"

    start on runlevel [2345]
    stop on runlevel [!2345]

    respawn

    script
    H_BEGIN="905"
    H_END="2330"
    H_NOW=$(date +%k%M)

    if [[ ${H_NOW} -gt ${H_BEGIN} && ${H_NOW} -lt ${H_END} ]]; then
    exec my_python_script
    fi
    end script


    but it doesn't seems to take the condition, even if i remove the "start on runlevel [2345]"



    i've already take a look here: http://upstart.ubuntu.com/faq.html#replace-cron




    You'd be able to have a service only running between particular times,
    or on particular days, etc.
    Blockquote




    But it's not made very clear.



    If somebody knows how to specify a between time to launch something by using upstart, it would be nice.










    share|improve this question

























      1












      1








      1








      I would like to run a script between two hours using upstart:




      • start at: 9h00

      • stop at: 23h30


      This is my upstart:



      author "bakka"

      start on runlevel [2345]
      stop on runlevel [!2345]

      respawn

      script
      H_BEGIN="905"
      H_END="2330"
      H_NOW=$(date +%k%M)

      if [[ ${H_NOW} -gt ${H_BEGIN} && ${H_NOW} -lt ${H_END} ]]; then
      exec my_python_script
      fi
      end script


      but it doesn't seems to take the condition, even if i remove the "start on runlevel [2345]"



      i've already take a look here: http://upstart.ubuntu.com/faq.html#replace-cron




      You'd be able to have a service only running between particular times,
      or on particular days, etc.
      Blockquote




      But it's not made very clear.



      If somebody knows how to specify a between time to launch something by using upstart, it would be nice.










      share|improve this question














      I would like to run a script between two hours using upstart:




      • start at: 9h00

      • stop at: 23h30


      This is my upstart:



      author "bakka"

      start on runlevel [2345]
      stop on runlevel [!2345]

      respawn

      script
      H_BEGIN="905"
      H_END="2330"
      H_NOW=$(date +%k%M)

      if [[ ${H_NOW} -gt ${H_BEGIN} && ${H_NOW} -lt ${H_END} ]]; then
      exec my_python_script
      fi
      end script


      but it doesn't seems to take the condition, even if i remove the "start on runlevel [2345]"



      i've already take a look here: http://upstart.ubuntu.com/faq.html#replace-cron




      You'd be able to have a service only running between particular times,
      or on particular days, etc.
      Blockquote




      But it's not made very clear.



      If somebody knows how to specify a between time to launch something by using upstart, it would be nice.







      upstart






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 14:00









      BakkaBakka

      84




      84
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This was never implemented as a part of upstart. I would suggest using the very simple tool snooze in conjunction with upstart. This is how I run my cron.{hourly,daily,weekly,monthly} scripts on void linux.



          For your particular case, starting the job at 9:00 and stopping it at 23:30, you would use three jobs like this:



          description "start my service if it is after 9:00 but before 23:30"
          emits start-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H9 -s870 -- initctl emit start-myservice


          description "stop my service if it is after 23:30 but before 9:00"
          emits stop-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H23 -M30 -s570 -- initctl emit stop-myservice


          description "my service"

          start on start-myservice
          stop on stop-myservice

          respawn
          exec my_python_script





          share|improve this answer
























          • Thanks a lot, this do what i want nicely

            – Bakka
            Nov 27 '18 at 10:03











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321134%2fupstart-run-script-between-particular-time%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This was never implemented as a part of upstart. I would suggest using the very simple tool snooze in conjunction with upstart. This is how I run my cron.{hourly,daily,weekly,monthly} scripts on void linux.



          For your particular case, starting the job at 9:00 and stopping it at 23:30, you would use three jobs like this:



          description "start my service if it is after 9:00 but before 23:30"
          emits start-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H9 -s870 -- initctl emit start-myservice


          description "stop my service if it is after 23:30 but before 9:00"
          emits stop-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H23 -M30 -s570 -- initctl emit stop-myservice


          description "my service"

          start on start-myservice
          stop on stop-myservice

          respawn
          exec my_python_script





          share|improve this answer
























          • Thanks a lot, this do what i want nicely

            – Bakka
            Nov 27 '18 at 10:03
















          0














          This was never implemented as a part of upstart. I would suggest using the very simple tool snooze in conjunction with upstart. This is how I run my cron.{hourly,daily,weekly,monthly} scripts on void linux.



          For your particular case, starting the job at 9:00 and stopping it at 23:30, you would use three jobs like this:



          description "start my service if it is after 9:00 but before 23:30"
          emits start-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H9 -s870 -- initctl emit start-myservice


          description "stop my service if it is after 23:30 but before 9:00"
          emits stop-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H23 -M30 -s570 -- initctl emit stop-myservice


          description "my service"

          start on start-myservice
          stop on stop-myservice

          respawn
          exec my_python_script





          share|improve this answer
























          • Thanks a lot, this do what i want nicely

            – Bakka
            Nov 27 '18 at 10:03














          0












          0








          0







          This was never implemented as a part of upstart. I would suggest using the very simple tool snooze in conjunction with upstart. This is how I run my cron.{hourly,daily,weekly,monthly} scripts on void linux.



          For your particular case, starting the job at 9:00 and stopping it at 23:30, you would use three jobs like this:



          description "start my service if it is after 9:00 but before 23:30"
          emits start-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H9 -s870 -- initctl emit start-myservice


          description "stop my service if it is after 23:30 but before 9:00"
          emits stop-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H23 -M30 -s570 -- initctl emit stop-myservice


          description "my service"

          start on start-myservice
          stop on stop-myservice

          respawn
          exec my_python_script





          share|improve this answer













          This was never implemented as a part of upstart. I would suggest using the very simple tool snooze in conjunction with upstart. This is how I run my cron.{hourly,daily,weekly,monthly} scripts on void linux.



          For your particular case, starting the job at 9:00 and stopping it at 23:30, you would use three jobs like this:



          description "start my service if it is after 9:00 but before 23:30"
          emits start-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H9 -s870 -- initctl emit start-myservice


          description "stop my service if it is after 23:30 but before 9:00"
          emits stop-myservice

          start on runlevel [2345]
          stop on runlevel [!2345]

          respawn
          exec snooze -H23 -M30 -s570 -- initctl emit stop-myservice


          description "my service"

          start on start-myservice
          stop on stop-myservice

          respawn
          exec my_python_script






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 3:03









          CameronNemoCameronNemo

          57625




          57625













          • Thanks a lot, this do what i want nicely

            – Bakka
            Nov 27 '18 at 10:03



















          • Thanks a lot, this do what i want nicely

            – Bakka
            Nov 27 '18 at 10:03

















          Thanks a lot, this do what i want nicely

          – Bakka
          Nov 27 '18 at 10:03





          Thanks a lot, this do what i want nicely

          – Bakka
          Nov 27 '18 at 10:03




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321134%2fupstart-run-script-between-particular-time%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python