How to run multiple scripts at a same time?
Clash 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
.
linux shell-script cron
add a comment |Â
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
.
linux shell-script cron
what OS are you running? do you have therun-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
add a comment |Â
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
.
linux shell-script cron
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
linux shell-script cron
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 therun-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
add a comment |Â
what OS are you running? do you have therun-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
add a comment |Â
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 ||
.
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
add a comment |Â
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.
add a comment |Â
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.
New contributor
add a comment |Â
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 ||
.
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
add a comment |Â
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 ||
.
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
add a comment |Â
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 ||
.
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 ||
.
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Jun 2 '16 at 11:55
answered Jun 2 '16 at 10:51
malyy
97747
97747
add a comment |Â
add a comment |Â
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.
New contributor
add a comment |Â
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.
New contributor
add a comment |Â
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.
New contributor
'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.
New contributor
New contributor
answered 8 mins ago
Chris C
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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