DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: Cron Job on first Monday of every month

  1. #1
    Join Date
    Feb 2000
    Location
    Washington DC
    Posts
    1,843
    How to setup Cron Job on first Monday of every month ?? -Thanks
    Reddy,Sam

  2. #2
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    first you must have the right to have a crontab, or login as root, then crontab -e (edit), and you add your line :
    min hour day_of_month month weekday
    to run something every first monday of every month at 8:15, just do :

    15 8 1-7 * 1 command

    that is to say you'll launch your command every monday that is between the 1st and 7th day of the month, that is to say the first monday ...

  3. #3
    Join Date
    Feb 2000
    Location
    Washington DC
    Posts
    1,843
    Got you. Thx
    Reddy,Sam

  4. #4
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Anybody got another idea for this? On Solaris, this entry would run at 8:15 on Monday's AND days 1-7.
    Jeff Hunter

  5. #5
    Join Date
    Jul 2000
    Posts
    521
    I guess, crontab entries are "OR"ed.
    So, 15 8 1-7 * 1 command will execute the 'command' on all Mondays and first 7 days of a month.

    So, unless there is a better way, the 'command' will have to take care of checking that "it really is first Monday of the Month".
    svk

  6. #6
    Join Date
    Dec 1999
    Location
    Cincinnati, Ohio USA
    Posts
    99
    This was interesting question so I posted it on unix.com, here is what Perderabo came up with....

    This usual solution is something like, first write a wrapper script that will run somecommand only if the day of the month is 7 or less:


    code:--------------------------------------------------------------------------------
    #! /usr/bin/ksh
    day=$(date +%d)
    if ((day <= 7)) ; then
    exec somecommand
    fi
    exit 1
    --------------------------------------------------------------------------------


    Then run the wrapper every Monday: "0 0 * * 1 wrapper".

    Doug

  7. #7
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    I was afraid of that. I think the "tacky" police will be hunting me down...
    Jeff Hunter

  8. #8
    Join Date
    Nov 2000
    Posts
    245

    We did same way,
    crontab, we scehdule daily base
    2 0 * * * myjob

    in the shell script:

    myjob code---------------------------------------
    wkdate=`date +%w`
    DD=`date +%d`

    # Mon - Fri, & Sun run daily process
    # Saturday run weekly process except:
    # the 1st Saturday of each month run monthly process

    case $wkdate in
    6)
    if [[ $DD -lt 8 ]] ; then
    echo run monthly process
    ./month_process.sh
    else
    echo run weekly process
    ./weekly_process.sh
    fi
    ;;
    *)
    echo run daily process
    ./daily_process.sh
    ;;
    esac
    ----------------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width