#!/bin/bash function wait_for { # param 1: hour to wait for echo "wait_for $1" while [ $1 -ne $(date +%H) ] do sleep 100 done } function process_hour { # param 1: hour to process echo "process_hour $1" if [ -d $base_dir/$1 ] then for file in $(ls $base_dir/$1) do $base_dir/$1/$file done fi } # default processing hour=$(date +%H) base_dir=/etc/cron.d # override current date, if 1st param is set if [ $# -ge 1 ] then hour=$1 fi hour=${hour#0} # override default dir, if 2st param is set if [ $# -ge 2 ] then base_dir=$2 fi # program #spawn cyclic jobs if [ -d $base_dir/periodic ] then for file in $(ls $base_dir/periodic) do $base_dir/periodic/$file & done fi # daily loop while true do process_hour $hour hour=$(expr $hour + 1) if [ $hour -eq 24 ] then hour=0 fi wait_for $hour done