Multiple scripts in one single script - crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple scripts in one single script - crontab
# 1  
Old 04-06-2017
Multiple scripts in one single script - crontab

Hello all,
Hope all's well.

i'm not sure if this is possible but i have some scripts running in a crontab with different intervals, 1min, 5 min, etc.

As for a "cleaner" and better control of these scripts (as by time we will have hundred's of scripts used for the same purpose, i.e for Nagios monitoring), i was wondering if these scripts can be integrated in a master script, let's say we call it Master_cron.sh.
This master script will run every minute but, here's my dilemma, the scripts inside will still need to run with different time intervals. Do you think this can be achieved somehow?
i was thinking maybe i can use the date/time command
Code:
date +%T

to set the script to run in intervals, but am not sure i'm in the right track.

Was thinking maybe i can use an indefinite loop something like:
Code:
while sleep 1m
do
    script 1 running every 1 minute, script 2 running every 1 min, etc.
    ....
done
while sleep 5m
do
    script 1 running every 5 minuts, script 2 running every 5 min, etc.
    ....
done

For using the while am not sure if the above is a correct syntax

Note that of course i need to be careful since these scripts run in the root cron, so i cannot overwrite the root cron. The OS is Solaris 10.

Thanks in advance.

Last edited by nms; 04-06-2017 at 05:38 PM..
# 2  
Old 04-06-2017
If I understand what you are asking correctly, you are saying that you have a variety of cron jobs scheduled separately using crontab. And, instead of having multiple scripts with separate entries in crontab you want to build all of those scripts into a single script that crontab will be used to run that script every minute and then that script will implement all of the features of cron and crontab to run parts of itself at appropriate intervals. If that is what you are trying to do, it sounds like you could spend a LOT of time duplicating the functionality of cron in your script, add overhead to the system and your script, and make it harder to track down issues if your scripts do not work as expected without adding any obvious benefits.

Why would you want to do this? Is it that you want to serialize all of your Nagios scripts so that they will not run concurrently (as they could when scheduled by cron)?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 04-07-2017
Like Don Cragun said, I really don't see a point in your goal, and why you try to reinvent cron, but if you really want to do:

You are thinking of an infinite loop. Well, in your example code, you had two infinite loops serialized, which is not very sensible, because you would have to wait an infinite time until the second loop starts. Not good.

So, you would have one infinite loop. This means that this program should not run as a cron job at all. An infinite loop program runs, at least in theory, forever, and hence should not go into cron. With other words, you want to replace a cron solution by a service (daemon).

If you do not want to write a real daemon, you can of course start your program manually, but you have to do it every time after a reboot. The problem is that programs can crash, so you would need a - now again - cron job, which periodically looks after your "cron clone" and restarts it if necessary.

Do you really want to go for this?

If you want to combine your scripts, I would write one master script for each 1-minute-nagios, another master script where I invoke the 5-miniute-nagios, and so on. Then I have only few cron jobs, one for each time interval.
This User Gave Thanks to rovf For This Post:
# 4  
Old 04-10-2017
Hi

You're both right. The idea was a management's request. I tend to agree that this will cause some overhead, but to go on both ways i guess it could be a good idea to setup one master script for different time intervals as rovf said.

Many thanks for you input!
# 5  
Old 04-10-2017
Quote:
Originally Posted by nms
The idea was a management's request.
This explains everything! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

A single script to run multiple scripts

Hi , Can someone help! I need a shell script to run multiple scripts by using single shell script, incase any one of the scripts fails, it should get exit and after trouble shooting if we re-execute it, it should start from the failed script. I have a written a scripting till the... (1 Reply)
Discussion started by: anniesurolyn
1 Replies

2. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (1 Reply)
Discussion started by: Madhu Siddula
1 Replies

3. Shell Programming and Scripting

Combining two scripts into a single script

Hi Folks, I have two scripts that are used to start and stop services these scripts are at the location /opt/app/tre , so that start.sh internally starts the components and stop.sh internally stop all the components, now rite now if I have to stop the services then i need to go first the... (9 Replies)
Discussion started by: punpun66
9 Replies

4. UNIX for Dummies Questions & Answers

Script for renaming multiple scripts

Hi There I am looking at writing a script that I can run from a cron job (say every month) that will copy my existing scripts to another folder, then in THAT new folder, append them all with the extension of .txt I have the cp command down pat (cp /existing_folder /new_folder) however I am... (6 Replies)
Discussion started by: orangepeel
6 Replies

5. Shell Programming and Scripting

Single script to create multiple directories

Hi , I want a script to create a directories at different locations. suppose i am on home/path/zone1. I want to create a directory of current month in this location. Then i want to create the same current month directory in home/path/zone2.like this for 9 diffrent zones. I can do this... (4 Replies)
Discussion started by: sv0081493
4 Replies

6. Shell Programming and Scripting

Script to execute multiple scripts

Hi All, I have 4 scripts to execute. Each one take anywhere from 3 -9 hours to run depending on what it's doing. I'm running one at a time then check back periodically to see if it's still going and if not, run the other. How can I put these scripts into another script so that they are... (5 Replies)
Discussion started by: bbbngowc
5 Replies

7. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

8. Shell Programming and Scripting

How to run the multiple scp from single script?

Dear Experts, how to run multiple scp commands from single scripts. In a directory oracle redo files accumulate. i would like to copy those redo logs to my standby server. For same i am using scp to copy the files. where i am monitoring that as it is sending the files sequentially most of... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

9. Shell Programming and Scripting

Trigger a script by consequtive scripts in crontab

Hello Friends, I've been searching solutions for an exceptional backup case recently, I need someone to guide me, suggest a method pls. In a production system we have backup scripts, they are run by cron one after another, and monthly. There is 1 hour difference between each consecutive script... (1 Reply)
Discussion started by: EAGL€
1 Replies

10. UNIX for Dummies Questions & Answers

Sh script to run multiple php scripts

I wrote a .sh script to run 5 php scripts. The problem is that it's running 1 then 2 then 3 in that order .... I want it to execute all 5 at ONCE.... nohup php /home/script1/script1.php && nohup php /home/script2/script2.php && nohup php /home/script3/script3.php && nohup php... (1 Reply)
Discussion started by: holyearth
1 Replies
Login or Register to Ask a Question