How to run multiple scripts at a same time?

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











up vote
3
down vote

favorite












Suppose I want to run five different scripts at 3 PM on every Saturday and I want to put all these scripts in a single script and run it using cron.










share|improve this question























  • what OS are you running? do you have the run-parts command?
    – cas
    Jun 2 '16 at 11:39










  • I'm using redhat linux.
    – Debasish
    Jun 2 '16 at 17:31










  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 13 '17 at 23:28














up vote
3
down vote

favorite












Suppose I want to run five different scripts at 3 PM on every Saturday and I want to put all these scripts in a single script and run it using cron.










share|improve this question























  • what OS are you running? do you have the run-parts command?
    – cas
    Jun 2 '16 at 11:39










  • I'm using redhat linux.
    – Debasish
    Jun 2 '16 at 17:31










  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 13 '17 at 23:28












up vote
3
down vote

favorite









up vote
3
down vote

favorite











Suppose I want to run five different scripts at 3 PM on every Saturday and I want to put all these scripts in a single script and run it using cron.










share|improve this question















Suppose I want to run five different scripts at 3 PM on every Saturday and I want to put all these scripts in a single script and run it using cron.







linux shell-script cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 23:27









Jeff Schaller

34.1k851113




34.1k851113










asked Jun 2 '16 at 10:43









Debasish

2215




2215











  • what OS are you running? do you have the run-parts command?
    – cas
    Jun 2 '16 at 11:39










  • I'm using redhat linux.
    – Debasish
    Jun 2 '16 at 17:31










  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 13 '17 at 23:28
















  • what OS are you running? do you have the run-parts command?
    – cas
    Jun 2 '16 at 11:39










  • I'm using redhat linux.
    – Debasish
    Jun 2 '16 at 17:31










  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 13 '17 at 23:28















what OS are you running? do you have the run-parts command?
– cas
Jun 2 '16 at 11:39




what OS are you running? do you have the run-parts command?
– cas
Jun 2 '16 at 11:39












I'm using redhat linux.
– Debasish
Jun 2 '16 at 17:31




I'm using redhat linux.
– Debasish
Jun 2 '16 at 17:31












If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
– Jeff Schaller
Apr 13 '17 at 23:28




If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
– Jeff Schaller
Apr 13 '17 at 23:28










3 Answers
3






active

oldest

votes

















up vote
6
down vote













You could do this in several ways:



Single cron entry



0 15 * * 6 job1; job2; job3


Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that.



Multiple cron entries



0 15 * * 6 job1
0 15 * * 6 job2
0 15 * * 6 job3


Or as you ask, combine them into



one script and one cron entry:



#!/bin/sh
job1
job2
job3

Cron:
0 15 * * 6 /path/to/above/wrapper-script.sh


The same note as above applies here; job2 and job3 run in sequence; change it to job1 && job2 && job3 (or some combination) as desired.



See: What are the shell's control and redirection operators? for more on && and ||.






share|improve this answer






















  • My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
    – forquare
    Jun 2 '16 at 11:52






  • 1




    The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
    – Jeff Schaller
    Jun 2 '16 at 11:58






  • 1




    Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
    – rustyx
    Oct 13 at 20:08










  • Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
    – Jeff Schaller
    Oct 13 at 20:27


















up vote
0
down vote













Here is an explanation of the crontab format.



# 1. Entry: Minute when the process will be started [0-60]
# 2. Entry: Hour when the process will be started [0-23]
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
# 4. Entry: Month of the year when the process will be started [1-12]
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
#
# all x min = */x


So according to this your 0 15 * * 6 would run 15:00 every Saturday.






share|improve this answer





























    up vote
    0
    down vote













    'At the same time' and 'simultaneously' can be taken to mean different things. I came here looking for the later.



    The 'multiple cron entries' ran simultaneously for me in Ubuntu 16.04.
    I tested this by pinging 3 different targets, then verified all 3 were running in ps, and a packet capture.



    All jobs started simultaneously, and not one after the other, which it what I wanted. Thanks for your answer Jeff.





    share








    New contributor




    Chris C 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
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f287166%2fhow-to-run-multiple-scripts-at-a-same-time%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      6
      down vote













      You could do this in several ways:



      Single cron entry



      0 15 * * 6 job1; job2; job3


      Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that.



      Multiple cron entries



      0 15 * * 6 job1
      0 15 * * 6 job2
      0 15 * * 6 job3


      Or as you ask, combine them into



      one script and one cron entry:



      #!/bin/sh
      job1
      job2
      job3

      Cron:
      0 15 * * 6 /path/to/above/wrapper-script.sh


      The same note as above applies here; job2 and job3 run in sequence; change it to job1 && job2 && job3 (or some combination) as desired.



      See: What are the shell's control and redirection operators? for more on && and ||.






      share|improve this answer






















      • My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
        – forquare
        Jun 2 '16 at 11:52






      • 1




        The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
        – Jeff Schaller
        Jun 2 '16 at 11:58






      • 1




        Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
        – rustyx
        Oct 13 at 20:08










      • Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
        – Jeff Schaller
        Oct 13 at 20:27















      up vote
      6
      down vote













      You could do this in several ways:



      Single cron entry



      0 15 * * 6 job1; job2; job3


      Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that.



      Multiple cron entries



      0 15 * * 6 job1
      0 15 * * 6 job2
      0 15 * * 6 job3


      Or as you ask, combine them into



      one script and one cron entry:



      #!/bin/sh
      job1
      job2
      job3

      Cron:
      0 15 * * 6 /path/to/above/wrapper-script.sh


      The same note as above applies here; job2 and job3 run in sequence; change it to job1 && job2 && job3 (or some combination) as desired.



      See: What are the shell's control and redirection operators? for more on && and ||.






      share|improve this answer






















      • My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
        – forquare
        Jun 2 '16 at 11:52






      • 1




        The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
        – Jeff Schaller
        Jun 2 '16 at 11:58






      • 1




        Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
        – rustyx
        Oct 13 at 20:08










      • Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
        – Jeff Schaller
        Oct 13 at 20:27













      up vote
      6
      down vote










      up vote
      6
      down vote









      You could do this in several ways:



      Single cron entry



      0 15 * * 6 job1; job2; job3


      Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that.



      Multiple cron entries



      0 15 * * 6 job1
      0 15 * * 6 job2
      0 15 * * 6 job3


      Or as you ask, combine them into



      one script and one cron entry:



      #!/bin/sh
      job1
      job2
      job3

      Cron:
      0 15 * * 6 /path/to/above/wrapper-script.sh


      The same note as above applies here; job2 and job3 run in sequence; change it to job1 && job2 && job3 (or some combination) as desired.



      See: What are the shell's control and redirection operators? for more on && and ||.






      share|improve this answer














      You could do this in several ways:



      Single cron entry



      0 15 * * 6 job1; job2; job3


      Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that.



      Multiple cron entries



      0 15 * * 6 job1
      0 15 * * 6 job2
      0 15 * * 6 job3


      Or as you ask, combine them into



      one script and one cron entry:



      #!/bin/sh
      job1
      job2
      job3

      Cron:
      0 15 * * 6 /path/to/above/wrapper-script.sh


      The same note as above applies here; job2 and job3 run in sequence; change it to job1 && job2 && job3 (or some combination) as desired.



      See: What are the shell's control and redirection operators? for more on && and ||.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 13 '17 at 12:36









      Community♦

      1




      1










      answered Jun 2 '16 at 11:29









      Jeff Schaller

      34.1k851113




      34.1k851113











      • My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
        – forquare
        Jun 2 '16 at 11:52






      • 1




        The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
        – Jeff Schaller
        Jun 2 '16 at 11:58






      • 1




        Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
        – rustyx
        Oct 13 at 20:08










      • Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
        – Jeff Schaller
        Oct 13 at 20:27

















      • My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
        – forquare
        Jun 2 '16 at 11:52






      • 1




        The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
        – Jeff Schaller
        Jun 2 '16 at 11:58






      • 1




        Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
        – rustyx
        Oct 13 at 20:08










      • Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
        – Jeff Schaller
        Oct 13 at 20:27
















      My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
      – forquare
      Jun 2 '16 at 11:52




      My interpretation was that the OP wanted to run each job in parallel. Using your first and third solutions would run each job serially, would it not? While solution three is more along the lines of what I though the OP was after, can you background/nohup the commands in the script to make them run in parallel when the wrapper script is run from cron?
      – forquare
      Jun 2 '16 at 11:52




      1




      1




      The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
      – Jeff Schaller
      Jun 2 '16 at 11:58




      The answers above do run serially; it's not clear to me either about the parallelism question. The title says "at the same time" yet the body says "all in one script".
      – Jeff Schaller
      Jun 2 '16 at 11:58




      1




      1




      Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
      – rustyx
      Oct 13 at 20:08




      Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
      – rustyx
      Oct 13 at 20:08












      Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
      – Jeff Schaller
      Oct 13 at 20:27





      Good clarification, thank you @rustyx. Only the Single cron entry would be serial as far as cron is concerned. The script would be a single cron job with serial components.
      – Jeff Schaller
      Oct 13 at 20:27













      up vote
      0
      down vote













      Here is an explanation of the crontab format.



      # 1. Entry: Minute when the process will be started [0-60]
      # 2. Entry: Hour when the process will be started [0-23]
      # 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
      # 4. Entry: Month of the year when the process will be started [1-12]
      # 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
      #
      # all x min = */x


      So according to this your 0 15 * * 6 would run 15:00 every Saturday.






      share|improve this answer


























        up vote
        0
        down vote













        Here is an explanation of the crontab format.



        # 1. Entry: Minute when the process will be started [0-60]
        # 2. Entry: Hour when the process will be started [0-23]
        # 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
        # 4. Entry: Month of the year when the process will be started [1-12]
        # 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
        #
        # all x min = */x


        So according to this your 0 15 * * 6 would run 15:00 every Saturday.






        share|improve this answer
























          up vote
          0
          down vote










          up vote
          0
          down vote









          Here is an explanation of the crontab format.



          # 1. Entry: Minute when the process will be started [0-60]
          # 2. Entry: Hour when the process will be started [0-23]
          # 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
          # 4. Entry: Month of the year when the process will be started [1-12]
          # 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
          #
          # all x min = */x


          So according to this your 0 15 * * 6 would run 15:00 every Saturday.






          share|improve this answer














          Here is an explanation of the crontab format.



          # 1. Entry: Minute when the process will be started [0-60]
          # 2. Entry: Hour when the process will be started [0-23]
          # 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
          # 4. Entry: Month of the year when the process will be started [1-12]
          # 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
          #
          # all x min = */x


          So according to this your 0 15 * * 6 would run 15:00 every Saturday.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 2 '16 at 11:55

























          answered Jun 2 '16 at 10:51









          malyy

          97747




          97747




















              up vote
              0
              down vote













              'At the same time' and 'simultaneously' can be taken to mean different things. I came here looking for the later.



              The 'multiple cron entries' ran simultaneously for me in Ubuntu 16.04.
              I tested this by pinging 3 different targets, then verified all 3 were running in ps, and a packet capture.



              All jobs started simultaneously, and not one after the other, which it what I wanted. Thanks for your answer Jeff.





              share








              New contributor




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













                'At the same time' and 'simultaneously' can be taken to mean different things. I came here looking for the later.



                The 'multiple cron entries' ran simultaneously for me in Ubuntu 16.04.
                I tested this by pinging 3 different targets, then verified all 3 were running in ps, and a packet capture.



                All jobs started simultaneously, and not one after the other, which it what I wanted. Thanks for your answer Jeff.





                share








                New contributor




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









                  'At the same time' and 'simultaneously' can be taken to mean different things. I came here looking for the later.



                  The 'multiple cron entries' ran simultaneously for me in Ubuntu 16.04.
                  I tested this by pinging 3 different targets, then verified all 3 were running in ps, and a packet capture.



                  All jobs started simultaneously, and not one after the other, which it what I wanted. Thanks for your answer Jeff.





                  share








                  New contributor




                  Chris C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  'At the same time' and 'simultaneously' can be taken to mean different things. I came here looking for the later.



                  The 'multiple cron entries' ran simultaneously for me in Ubuntu 16.04.
                  I tested this by pinging 3 different targets, then verified all 3 were running in ps, and a packet capture.



                  All jobs started simultaneously, and not one after the other, which it what I wanted. Thanks for your answer Jeff.






                  share








                  New contributor




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




                  Chris C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 8 mins ago









                  Chris C

                  1




                  1




                  New contributor




                  Chris C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Chris C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Chris C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f287166%2fhow-to-run-multiple-scripts-at-a-same-time%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?