How can I set cron to run certain commands every one and a half hours?
#! /bin/sh
# Minute Cron
# Usage: cron-min start
# Copyright 2014 by Marc Perkel
# docs at http://wiki.junkemailfilter.com/index.php/How_to_run_a_Linux_script_every_few_seconds_under_cron"
# Free to use with attribution
# Run this script under Cron once a minute
basedir=/etc/cron-min
if [ $# -gt 0 ]
then
echo
echo "cron-min by Marc Perkel"
echo
echo "This program is used to run all programs in a directory in parallel every X minutes."
echo
echo "Usage: cron-min"
echo
echo "The scheduling is done by creating directories with the number of minutes as part of the"
echo "directory name. The minutes do not have to evenly divide into 60 or be less than 60."
echo
echo "Examples:"
echo " /etc/cron-min/1 # Executes everything in that directory every 1 minute"
echo " /etc/cron-min/5 # Executes everything in that directory every 5 minutes"
echo " /etc/cron-min/13 # Executes everything in that directory every 13 minutes"
echo " /etc/cron-min/90 # Executes everything in that directory every 90 minutes"
echo
exit
fi
for dir in $basedir/* ; do
minutes=${dir##*/}
if [ $(( ($(date +%s) / 60) % $minutes )) -eq 0 ]
then
for program in $basedir/$minutes/* ; do
if [ -x $program ]
then
$program &> /dev/null &
fi
done
fi
done
Two lines in the crontab. Along the lines of:
0 0,3,6,9,12,15,18,21 * * * /usr/bin/foo
30 1,4,7,10,13,16,19,22 * * * /usr/bin/foo
*/10 * * * * root perl -e 'exit(time()%(90*60)>60)' && command
90 — it is one and a half hour in minutes
"> 60" — I give to cron ability to delay the start of script during a minute
Also with help of this hack you can set any period with a minute resolution
For example start the script every 71 minutes
* * * * * root perl -e 'exit(time()%(71*60)>60)' && command