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
.
Asked
Active
Viewed 2.2k times
4

Jeff Schaller
- 67,283
- 35
- 116
- 255

Debasish
- 87
2 Answers
9
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 ||
.

Jeff Schaller
- 67,283
- 35
- 116
- 255
-
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 02 '16 at 11:52
-
1The 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 02 '16 at 11:58
-
1Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial? – rustyx Oct 13 '18 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 '18 at 20:27
0
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.

malyy
- 2,177
run-parts
command? – cas Jun 02 '16 at 11:39