Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing a cronfile

Status
Not open for further replies.

dendenners

Programmer
Jul 17, 2001
110
IE
Hi,
I need to parse a cron file and find out when a specific job will next be executed on my aix box. Has anyone here seen a script to do this, and if not, do people think that awk would be powerful enough to decipher any crontab entry, including ranges, multiple comma-seperated entries and combined day-of-month/day-of-week entries or would I have to use perl?
Thanks
Denis
 
I say that awk (or sed) is easily powerful enough, however it would be overkill unless your crontab is huge. Just a visual check is probably fine, however if you want to awk the results for some reason you can use `crontab -l` which will simply list the crontab, then pipe to an awk prog.

If you need help with awk, I highly recommend the O'Reilly book on "sed & awk", or try the awk forum here. IBM Certified -- AIX 4.3 Obfuscation
 
Try this batch script ;

# Get the current crontab entries
crontab -l | grep -v "^#" > tmpfile

# Show jobs ready to run today.
TODAY=`date +%w`
echo "------------------------------------------------------------------"
echo "Checking jobs for day $TODAY , `date +%A`..."
# mn=min , hr=hour , dy=month day , mt=month , wd=week day , cd=command
cat tmpfile | while read mn hr dy mt wd cd
do
START=`echo $wd | cut -f1 -d"-"`
END=`echo $wd | cut -f2 -d"-"`
# Cater for comma delimited day list
if ( echo $wd | grep -c "," >/dev/null )
then
wd1=`echo $wd | cut -f1 -d","`
wd2=`echo $wd | cut -f2 -d","`
wd3=`echo $wd | cut -f3 -d","`
wd4=`echo $wd | cut -f4 -d","`
wd5=`echo $wd | cut -f5 -d","`
START=$wd1
END=$wd3
if [ $TODAY = $wd1 -o $TODAY = $wd2 -o $TODAY = $wd3 ]
then
echo "At $hr:$mn ; $cd"
fi
else
if [ $TODAY = $wd -o $TODAY -ge $START -a $TODAY -le $END ]
then
echo "At $hr:$mn ; $cd"
# If this is a schedule,check it.
if ( grep -ci "sched" $cd >/dev/null)
then
SCHD=`echo $cd | cut -f4 -d/ `
fi
elif [ "$wd" = "*" ]
then
echo "At $hr:$mn ; $cd"
fi
fi
done

#End
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top