How to run multiple scripts at a same time?

18,045

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:
18,045

Related videos on Youtube

Debasish
Author by

Debasish

Updated on September 18, 2022

Comments

  • Debasish
    Debasish almost 2 years

    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.

    • Alessio
      Alessio about 8 years
      what OS are you running? do you have the run-parts command?
    • Debasish
      Debasish about 8 years
      I'm using redhat linux.
    • Jeff Schaller
      Jeff Schaller about 7 years
      If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
  • forquare
    forquare about 8 years
    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?
  • Jeff Schaller
    Jeff Schaller about 8 years
    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".
  • rustyx
    rustyx over 5 years
    Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
  • Jeff Schaller
    Jeff Schaller over 5 years
    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.