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 ||
.
Related videos on Youtube
![Debasish](https://i.stack.imgur.com/tNMlI.jpg?s=256&g=1)
Author by
Debasish
Updated on September 18, 2022Comments
-
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 about 8 yearswhat OS are you running? do you have the
run-parts
command? -
Debasish about 8 yearsI'm using redhat linux.
-
Jeff Schaller about 7 yearsIf any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
-
-
forquare about 8 yearsMy 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 about 8 yearsThe 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 over 5 yearsCron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
-
Jeff Schaller over 5 yearsGood 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.