Saturday, May 10, 2014

Crontab skip holiday date

Here's the step for skip holiday when using crontab:

1. Create the list of holidays on text file

touch /Users/arul/holidays_2014.txt
nano /Users/arul/holidays_2014.txt
2014-01-01
2014-01-14
2014-01-30
2014-03-31
2014-04-18

2. Create shell script on file

touch /Users/arul/runner.sh
nano /Users/arul/runner.sh
TODAY=$(date "+%Y-%m-%d")
if grep -q "$TODAY" /Users/arul/holiday.txt;
then
  /usr/bin/php /Users/arul/test.php
else
  echo "Not found the date"
  exit 0
fi

3. Set the Crontab task

crontab -e
Example the crontab will run every two hours start from Monday through Friday
0 */2 * * mon-fri sh /Users/arul/runner.sh

No comments:

Post a Comment