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.
# 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
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