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!

Setting cronjob time 3

Status
Not open for further replies.

unmlobo

MIS
Apr 11, 2003
64
US
I need to set a job to run every 1st Sunday of every month. I can set the time but I'm unsure of how to set the month and day. Anyideas? Thanks all!
 

Did you try:

00 08 1-7 * 0 /Mydir/Myjob.sh





----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Wouldn't that run from the first of the month to the seventh of the month? I just need it on the first Sunday of every month.
 
No, the 0 (zero) says: run only on sunday.

For example: Run at 8:00 am every month (*) from day 1 thru day 7 on SUNDAY only.


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Never thought about it like that but it make perfect sense. Thanks for the info.
 
LkBrnDBA, have you tested this? Not to be a pain but I think I tried this once and my job ran on the first 7 days of the month and on every Sunday. The man page has a similar example.

To accomplish the task, unmlobo, you may want to just add some logic to your script (or script the job as it were) that will only run the job if the output of the 'date +%d' is between 1 and 7. And, of course, just tell cron to run it on Sunday.

HTH
Brian
 
From the Solaris man page.

"Example 3: Specifying days of the month and week

This example

0 0 1,15 * 1
would run a command on the first and fifteenth of each month, as well as on every Monday."

I just wanted to elaborate on my post and reiterate that LKBrwnDBA's example will not fulfill the requirement. For some reason he has received 2 stars, though? I don't understand.

Brian
 
Thanks for the info Brian. The reason I gave LKBrwnDBA a star is because they took the time to answer the question for me. The answer may not have been right but it did lead me on the right path. I was showing my appreciation for that reason. I also gave you a star because u did the same. Thanks again!
 
Thanks, as a bonus here is a script that returns the number of the bussines day, helpfull when you want something to execute on the n'th business day of the month:
Code:
#!/bin/ksh
#
# chk_business_day.sh
#
# Returns the number of business day.
#
# Set up in your script as:
#
#  if [ chk_business_day.sh -eq 5 ]
#  then
#    echo "It's the fifth business day of the month!"
#  fi
#
# Requires ${LOC}_holidays.dat table as list of holidays:
# YYYYMMDD Holiday reason1
# YYYYMMDD Holiday reason2
# etc...
# Located at: $BASECFG/${LOC}_holidays.dat
# and $LOC = Country code
# ------------------------------------------------------------------------
#  5/16/02    MOrtizM     Initial coding
#  8/20/02    MOrtizM     Corrected the business-day calculation and
#                         changed to return the number of business days
# ------------------------------------------------------------------------
# 1 # Country code of holiday file
LOC=$(echo ${1:=US}|tr [:lower:] [:upper:])
#
# ------------------------------------------------------------------------
BASECFG=/oracle/local/tmp
CURDT=$(date +%Y%m%d)
today=$(date +%d)
YYYYMM=$(date +%Y%m)
DOW=$(date +%w)
if [ ! -f $BASECFG/${LOC}_holidays.dat ]
then
  echo "# ${LOC}_holidays table as of `date`" > $BASECFG/${LOC}_holidays.dat
fi
# Return if Saturday or Sunday
if [[ $DOW -eq 0 || $DOW -eq 6 ]]
then
  return 0
fi
# Return if Holiday
if test  $(grep "^${CURDT}" $BASECFG/${LOC}_holidays.dat|wc -l) -gt 0
then
  return 0
fi
bus_day=0
for dd in 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17           16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01
do
  if test $dd -le $today
  then
    if [[ ! $DOW -eq 0 && ! $DOW -eq 6 ]]
    then
      if test  $(grep "^${YYYYMM}$dd" $BASECFG/${LOC}_holidays.dat|wc -l) -eq 0
      then
        ((bus_day += 1))
      fi
    fi
    ((DOW = DOW - 1))
    if test $DOW -lt 0
    then
      DOW=6
    fi
  fi
done
return $bus_day

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top