Scheduling scheduling !!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scheduling scheduling !!!
# 1  
Old 01-31-2012
Scheduling scheduling !!!

Hi,

i have 10 sh scripts. All are running in parallel using cron tab and each script gives "success" flag files once the execution is completed.

and, now i have 11th script which should look for "success" flag from those 10 sh scripts. once all the 10 flag files found, 11 th script has to do some action.

how can i write the logic for 11 th script and how could it be scheduled ?

Any suggessions ?


Thank You ,
nago
# 2  
Old 01-31-2012
cron is a very poor way to do this. I'd recommend using a makefile instead.

Code:
$ cat Makefile

# Note that the eight spaces in front of things are actually tabs and MUST BE TABS
# for the makefile to work correctly.
all:j1 j2 j3 j4 j5 j6 j7 j8 j9 j10
        echo "all jobs complete"

j1:
        sleep 1 ; echo $@
j2:
        sleep 1 ; echo $@
j3:
        sleep 1 ; echo $@
j4:
        sleep 1 ; echo $@
j5:
        sleep 1 ; echo $@
j6:
        sleep 1 ; echo $@
j7:
        sleep 1 ; echo $@
j8:
        sleep 1 ; echo $@
j9:
        sleep 1 ; echo $@
j10:
        sleep 1 ; echo $@

$ make

sleep 1 ; echo j1
j1
sleep 1 ; echo j2
j2
sleep 1 ; echo j3
j3
sleep 1 ; echo j4
j4
sleep 1 ; echo j5
j5
sleep 1 ; echo j6
j6
sleep 1 ; echo j7
j7
sleep 1 ; echo j8
j8
sleep 1 ; echo j9
j9
sleep 1 ; echo j10
j10
echo "all jobs complete"
all jobs complete

# Takes 10 seconds to run each job individually
$ time make

sleep 1 ; echo j1
j1
sleep 1 ; echo j2
j2
sleep 1 ; echo j3
j3
sleep 1 ; echo j4
j4
sleep 1 ; echo j5
j5
sleep 1 ; echo j6
j6
sleep 1 ; echo j7
j7
sleep 1 ; echo j8
j8
sleep 1 ; echo j9
j9
sleep 1 ; echo j10
j10
echo "all jobs complete"
all jobs complete

real    0m10.032s
user    0m0.006s
sys     0m0.009s

# ...but only one when you run all the echo's in parallel
$ time make -j 10
sleep 1 ; echo j1
sleep 1 ; echo j2
sleep 1 ; echo j3
sleep 1 ; echo j4
sleep 1 ; echo j5
sleep 1 ; echo j6
sleep 1 ; echo j7
sleep 1 ; echo j8
sleep 1 ; echo j9
sleep 1 ; echo j10
j1
j2
j3
j4
j5
j7
j6
j8
j9
j10
echo "all jobs complete"
all jobs complete

real    0m1.017s
user    0m0.009s
sys     0m0.007s

$

If you insist, you should even be able to run make from cron, like this:

Code:
/usr/bin/make -C /path/to/dir/ -j 10 2> /dev/null

which will cause it to run the Makefile inside /path/to/dir.
# 3  
Old 01-31-2012
but , where are we mentioning the scheduling time for 10 jobs ? they should start run in parallel at 8 AM everyday .

-nago
# 4  
Old 01-31-2012
You'd put that before /usr/bin/make. Then it will start the ten jobs at parallel at that time, and wait for them all to finish before running whatever command you put in the 'all' rule.
# 5  
Old 01-31-2012
any link to get to know "make" command more detailed ?

-nago
# 6  
Old 01-31-2012
first google hit for introduction to make

Note that 'make' is often used with rules matching files. This is done so that, if the rule matches a file, and the file is newer than its dependencies, it won't be rebuilt. If the rule doesn't produce a file, it will be run every time.

Last edited by Corona688; 01-31-2012 at 02:26 PM..
# 7  
Old 01-31-2012
Another approach is to use the Shell's own background job management and handle the whole lot in one controlling script called from one cron.

This example runs "ls" 10 times concurrently in background, waits until all 10 jobs have finished, then checks for 10 success flag files.

Code:
ls >/tmp/success1 &
ls >/tmp/success2 &
ls >/tmp/success3 &
ls >/tmp/success4 &
ls >/tmp/success5 &
ls >/tmp/success6 &
ls >/tmp/success7 &
ls >/tmp/success8 &
ls >/tmp/success9 &
ls >/tmp/success10 &
#
# Sleep until all 10 background jobs finish
while true
do
        [ ! "`jobs`" ] && break
        sleep 10
done
#
# Check success flags
if [ -f /tmp/success1 -a -f /tmp/success2 -a -f /tmp/success3 \
  -a -f /tmp/success4 -a -f /tmp/success5 -a -f /tmp/success6 \
  -a -f /tmp/success7 -a -f /tmp/success8 -a -f /tmp/success9 \
  -a -f /tmp/success10 ]
then
        echo "11th job goes here"
else
        echo "One or more jobs failed"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Scheduling a script

Hi, I have my script in below path in UNIX /storage/sas_source/SDTM-Development/FileWatcher/filewatcher.sh I want to schedule it to run every 30 secs. Please let me know the steps to do it. Thanks. (7 Replies)
Discussion started by: prats_7678
7 Replies

2. Shell Programming and Scripting

Scheduling issues

I AM ON SOLARIS I have a script it.sh which is running fine when i execute it from shell command. But when i schedule it in crontab it is throwing error. Why and how can i resolve it ?i am clueless IT.SH #!/bin/sh ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME... (1 Reply)
Discussion started by: rafa_fed2
1 Replies

3. Shell Programming and Scripting

help required on scheduling

hi I have a script, abc.sh first time user will start a script using <<abc.sh start >>, inside a script using " at " i am schduling same script for every one hour. so my script always running . total script execution time takes around 1sec for closing same << abc.sh stop>> here... (2 Replies)
Discussion started by: pvr_satya
2 Replies

4. Shell Programming and Scripting

Crontab scheduling

Hi all, My OS is Solaris 10. I want to schedule a job which i need to run between morining 6 to eve 6 once for every 2 hours. This is what i did. 0 6-18 * * 1-5 /monitor.sh It runs for every hour how to make it for every two hours ...... Thanks, Firestar. (1 Reply)
Discussion started by: firestar
1 Replies

5. Linux

Help with cronjob scheduling

Hi Everybody, How to schedule a job using cron that shouldn't run between working hrs 9am-5pm, while run in non working hrs every hour, every day of the month, month & week. I tried the following way, not sure I can use logical not operator(!). Please correct me if wrong or suggest other... (2 Replies)
Discussion started by: sudhirav
2 Replies

6. Programming

Time scheduling

Hello !!! i am trying to create a command scheduler (written in C). Basically i would like to do what the "at" command does , but without using "at" or "cron". I have tried using getitimer but i do not know how can i shcedule multiple commands. Any ideas ??? (2 Replies)
Discussion started by: mcnikolas
2 Replies

7. Shell Programming and Scripting

Job Scheduling

I am working on UNIX AIX system, with Oracle OS. We are not supposed to use any tools to schedule our unix shell scripts. Basically we have to make use of Oracle tables and Shell scripts to manage dependencies, restartability, scheduling, parallelizing,etc. If anyone has worked/ is working... (4 Replies)
Discussion started by: singhabhijit
4 Replies

8. UNIX and Linux Applications

Job Scheduling

I am working on UNIX AIX system, with Oracle OS. We are not supposed to use any tools to schedule our unix shell scripts. Basically we have to make use of Oracle tables and Shell scripts to manage dependencies, restartability, scheduling, parallelizing,etc. If anyone has worked/ is working... (1 Reply)
Discussion started by: singhabhijit
1 Replies

9. HP-UX

cron scheduling?

Hi all, i want a job to run first monday of every of month. (1 Reply)
Discussion started by: megh
1 Replies

10. UNIX for Dummies Questions & Answers

scheduling

i have tried to schedule my process at a certain time using the at command : the error says bad time specification can somebody help me i used at 2300 job thanks (2 Replies)
Discussion started by: prashantuc
2 Replies
Login or Register to Ask a Question