NewOldUser --- Another Grumpy Old Man


fauxCron script 

I've been trying to post this script. It's been a problem posting the code on a site that will not alter it. Lets see how this site does.

The original write up can be found at: NewOldUsers Damn Small Linux Blog Page 

 

#!/bin/bash
version="2.10"
# fauxCron.sh for those without a cron...
#
# Required files:
#
#  1. cronIN.txt
#
#      Last line contains "<end>" in cols 1-5
#
#      All other lines should have timestamp in col 1-12 YYYYMMDDHHMM
#                                                     or -----DOWHHMM (DOW = Day of Week, dashes are needed)
#                                                 blank in col 13
#                                                 command to be executed starting in col 14
#
#
#   2. cronLOG.txt
#
#      As commands are executed they are copied to this file with the
#      timestamp when they were executed put in front.
#
#
# Temporary file:
#
#   1. cronOUT.txt - temporary file that becomes cronIN.txt
#
# changelog add at version 1.04
# v1.04 - added changelog
#         commented out echo fauxCron checking...
# v2.00 - - added day of week checking using date +%a
#         - no 'catch up' processing is done. If an event is missed it must be rescheduled
#         - change all back-tick commands to $(command) for easier reading
# v2.10 - move the activityThisRun=NO to be inside the DO loop
#
while true
do
activityThisRun="NO"
exec 3< cronIN.txt
thisRun=$(date +%Y%m%d%H%M)
thisRunDOW=$(date +%a%H%M)
#echo $thisRun $thisRunDOW "fauxCron checking..."
read taskTime taskCommand <&3
while [ "$taskTime" != "<end>" ]
do
    #echo "taskTime = " $taskTime "$taskTime"
    if [ "$taskTime" == "$thisRun" ] || [ "$taskTime" == "-----$thisRunDOW" ]; then
      nice $taskCommand &
       echo $thisRun $taskTime $taskCommand >> cronLOG.txt
      activityThisRun="YES"
      case $taskTime in
        -*)
        echo $taskTime $taskCommand >> cronOUT.txt;;
      esac
    else
      echo $taskTime $taskCommand >> cronOUT.txt
    fi
    read taskTime taskCommand <&3
done
echo "<end>" >> cronOUT.txt
exec 3>&-
if [ $activityThisRun == "YES" ]; then
    rm -f cronIN.txt
    cat cronOUT.txt > cronIN.txt
fi
rm -f cronOUT.txt
#sleep for 60 seconds if you set this to less then 60 then
#you run the risk of a weekly task (-----Mon1150) running twice
#in the same minute
sleep 60s
done
exit 0 

#end of script


See the stopTask script See additional scripts and support files