How to schedule a Unix shell script in crontab to run every 2nd Saturday(nth Day of the month)

There is no direct way to schedule the script in crontab for nth day of every month. Which means suppose if you wanted to execute the shell script for every 2nd Saturday or every 3rd Monday, etc. (i.e: The execution occurrence will be one in a month; nth Sunday, Monday, Teusday, Wednesday, Thursday, Friday or Saturday) Crontab will not support this. You have to write your own code to execute this. A sample code is given below.
TODAY=`/bin/date +%d | cut -d"0" -f2`
DAY=`cal | awk {'print $7'} | xargs | /usr/bin/cut -d" " -f3`
#See if today matches the 2nd Tuesday of the month
if [ "$TODAY" -ne "$DAY" ] ; then
echo "Today is not Second Saturday"
echo "Today is 2nd Saturday. Please put your program code just below."
DBA Tips Data Pump Reference


Post a Comment


dba topics. Copyright 2011-17 All Rights Reserved | Site Map | Contact | Disclaimer | Google