4

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.

3
  • what OS are you running? do you have the run-parts command?
    – cas
    Commented Jun 2, 2016 at 11:39
  • I'm using redhat linux.
    – Debasish
    Commented Jun 2, 2016 at 17:31
  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Commented Apr 13, 2017 at 23:28

2 Answers 2

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 ||.

4
  • 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
    Commented Jun 2, 2016 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
    Commented Jun 2, 2016 at 11:58
  • 1
    Cron doesn't wait for completion of jobs; how can the "Multiple cron entries" option be serial?
    – rustyx
    Commented Oct 13, 2018 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
    Commented Oct 13, 2018 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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .