Forum Moderators: coopster & phranque

Message Too Old, No Replies

I have like 50 crons that need to run sequentially

Sequential Cron Jobs

         

Nosmada

8:22 am on Feb 22, 2006 (gmt 0)

10+ Year Member



Hello all.

How do I have it so that one cron starts and finishes then the next one starts and finishes and so on until they are all done?

My aim is that the server only has to be bogged down with one cron job at any given time rather than guessing when to schedule each and ending up with overlapping cron jobs hitting the server at the same time.

zCat

8:29 am on Feb 22, 2006 (gmt 0)

10+ Year Member



How about creating a shell script which calls up the actual cron jobs sequentially, and only setting up one cronjob. i.e. this script?

Make sure the script sets a lockfile so two instances won't run at the same time.

Frank_Rizzo

9:04 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As the previous poster says - use a script and check for lock files if you must.


# Big Script File
# Run via cron at midnight
#
if! test -f /home/mysite/status/hold*
then
cp /home/mysite/status/flag /home/mysite/status/hold_big_script_running
fi
./app_1 #run a compiled app
perl perl_app_1 #run a perl script
php php_app_1 #run a php file
rm /home/mysite/status/hold_big_script_running
fi

SeanW

1:34 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



If you're using Linux, look at run-parts. If not, it's just a shell script, you can copy it (below)

You put all your jobs in a single directory and call run-parts on it from cron. It executes all the jobs sequentially, and since it's one cron job, all the output goes as one single email.

Sean

# run-parts - concept taken from Debian

# keep going when something fails
set +e

if [ $# -lt 1 ]; then
echo "Usage: run-parts <dir>"
exit 1
fi

if [! -d $1 ]; then
echo "Not a directory: $1"
exit 1
fi

# Ignore *~ and *, scripts
for i in $1/*[^~,] ; do
[ -d $i ] && continue
# Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
[ "${i%.rpmsave}"!= "${i}" ] && continue
[ "${i%.rpmorig}"!= "${i}" ] && continue
[ "${i%.rpmnew}"!= "${i}" ] && continue
[ "${i%.swp}"!= "${i}" ] && continue
[ "${i%,v}"!= "${i}" ] && continue

if [ -x $i ]; then
$i 2>&1 ¦ awk -v "progname=$i" \
'progname {
print progname ":\n"
progname="";
}
{ print; }'
fi
done

exit 0