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 ?
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.
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.
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.
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
The "jobs" command refers to background jobs running on the current terminal session. You did not background "common.sh" (with an & command) and therefore it ran in foreground.
Looking at "jobs" in another terminal window is irrelvant.