Re: crontab entry help (356 Views)
Reply
Super Advisor
rajesh73
Posts: 448
Registered: ‎03-17-2009
Message 1 of 3 (363 Views)

crontab entry help

 

Hi,

 

i want to disable the script every 1st and 3rd starturday. please help how make a crontab entry.

 

 

30 5 * * * /home/app.sh

 

 

Acclaimed Contributor
Dennis Handly
Posts: 25,277
Registered: ‎03-06-2006
Message 2 of 3 (356 Views)

Re: crontab entry help

>i want to disable the script every 1st and 3rd Saturday. please help how make a crontab entry.

 

You can not.  You must put these checks into the script, since cron only ORs specs like that.

Add this near the top of your script:

# Check 2 & 3 Sat

set -A dates $(date +"%e %w")
#echo "Day, weekday: ${dates[0]}:${dates[1]}"

if (( ${dates[1]} == 6 && ${dates[0]} >= 8 && ${dates[0]} <= 21 )); then
   echo "Skipping second and third Saturdays"
   exit 0
fi

Valued Contributor
RAJD1
Posts: 60
Registered: ‎10-09-2011
Message 3 of 3 (350 Views)

Re: crontab entry help

 

Hi, 

 

- As per 1st & 3rd saturday to skip , per Dennis's script : you can use like below, in your script at the begining:

-Nothing can be done in the crontab entries.

 

 

Add this near the top of your script:

-----------

# Check 1st & 3rd  Satday to skip.

set -A dates $(date +"%e %w")
#echo "Day, weekday: ${dates[0]}:${dates[1]}"

 

# For 1st Saturday.
if (( ${dates[1]} == 6 && ${dates[0]} >= 1 && ${dates[0]} <=7 )); then
   echo "Skipping First  Saturdays"

   exit 0

fi

 

 

# For 3rd Saturday: 

if (( ${dates[1]} == 6 && ${dates[0]} >= 15 && ${dates[0]} <=21 )); then
   echo "Skipping Third   Saturdays"

   exit 0

fi

 

# End 1st/3rd satday skip check function.

-------------

 

 

 

Hth,

Raj D.

 

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.