End of Month - Cron Jobs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting End of Month - Cron Jobs
# 1  
Old 01-28-2009
End of Month - Cron Jobs

I am running AIX 5.3 with the default shell as ksh.

I would like to know how to run a cron job on this system the last calendar day of the month. I found an example, but, I'm not sure if it will work with AIX and ksh...

Code:
02 16 * * * [ $(date +%d) -eq $(echo $(cal) | awk '{print $NF}') ] && /home/user/job-eom.ksh

I also need to be able to run a job on every day except the last calendar of the month (actually a series of jobs, but, I assume I can adopt the syntax for multiple jobs).

So to summarize:

I would like to run the following jobs where specified EXCEPT on the LAST calendar day of the month.

Code:
50   21   *   *   *   /home/user/eod-job1.ksh
00   22   *   *   *   /home/user/eod-job2.ksh
10   22   *   *   0   /home/user/eod-job3.ksh
10   22   *   *   1-4   /home/user/eod-job4.ksh
00   23   *   *   1   /home/user/eod-job5.ksh
10   22   *   *   5-6   /home/user/eod-job6.ksh
50   4    *   *   *   /home/user/eod-job7.ksh

And I would like to run another job ON the LAST calendar day of the month, and probably a couple of others...

Code:
45   20   *   *   *   /home/user/eom-job1.ksh

I'm also fairly new at shell scripting, etc., especially ksh.
# 2  
Old 01-28-2009
Quote:
Originally Posted by jthompson333
I am running AIX 5.3 with the default shell as ksh.

I would like to know how to run a cron job on this system the last calendar day of the month. I found an example, but, I'm not sure if it will work with AIX and ksh...

Code:
02 16 * * * [ $(date +%d) -eq $(echo $(cal) | awk '{print $NF}') ] && /home/user/job-eom.ksh

I also need to be able to run a job on every day except the last calendar of the month (actually a series of jobs, but, I assume I can adopt the syntax for multiple jobs).

So to summarize:

I would like to run the following jobs where specified EXCEPT on the LAST calendar day of the month.

Code:
50   21   *   *   *   /home/user/eod-job1.ksh
00   22   *   *   *   /home/user/eod-job2.ksh
10   22   *   *   0   /home/user/eod-job3.ksh
10   22   *   *   1-4   /home/user/eod-job4.ksh
00   23   *   *   1   /home/user/eod-job5.ksh
10   22   *   *   5-6   /home/user/eod-job6.ksh
50   4    *   *   *   /home/user/eod-job7.ksh

And I would like to run another job ON the LAST calendar day of the month, and probably a couple of others...

Code:
45   20   *   *   *   /home/user/eom-job1.ksh

I'm also fairly new at shell scripting, etc., especially ksh.
Code:
_days_in_month() ## USAGE: days_in_month [month [year]]
{
    case ${1#0} in
        9|4|6|11) _DAYS_IN_MONTH=30 ;; ## 30 days hath September...
        1|3|5|7|8|10|12) _DAYS_IN_MONTH=31 ;;
        2) is_leap_year ${2:-`date +%Y`} && _DAYS_IN_MONTH=29 || _DAYS_IN_MONTH=28 ;;
        *) return 5 ;;
    esac
}

is_leap_year() {
    [ $(( $1 % 4 ))   -eq 0 ] &&
    [ $(( $1 % 100 )) -ne 0 ] ||
    [ $(( $1 % 400 )) -eq 0 ]
}

eval "$( date +"year=%Y month=%m day=%d" )"

_days_in_month "$month" "$year"

if [ $_DAYS_IN_MONTH = ${day#0} ]
then
  : last day of month
else
  : not last day of month
fi

# 3  
Old 01-28-2009
So...

Would I use this script for every job and just insert my ksh script (or my jobs) in the appropriate part of the if statement?

How might I combine this with cron?

Again I am fairly new at this whole thing...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron Jobs

How to see which cron jobs are not running? (2 Replies)
Discussion started by: rahul.raj1989
2 Replies

2. UNIX for Dummies Questions & Answers

Get the next month end date

how to get the next month end date. dt=01312014 output=02282014 (2 Replies)
Discussion started by: w020637
2 Replies

3. Shell Programming and Scripting

Cron for end of month

Hello, I'm on FreeBSD 8.2-STABLE shell and I was trying the following cron entry for end of month: 59 23 * * * && /home/user/eomt.sh >/dev/null 2>&1 I get the following error Subject: Cron <user@shell> eomt.sh contains the following codes #!/bin/sh rm /home/user/tst/logs/* &&... (9 Replies)
Discussion started by: user`
9 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Cancelling print jobs for an entire month

Hi pals, Pls tel me how to cancel print jobs for an entire month (ex : sept)? lpstat -oLBNDUIP061 | grep -i Sep is listing me hundreds of jobs. Thanks in Advance, Satish Video tutorial on how to use code tags in The UNIX and Linux Forums. (22 Replies)
Discussion started by: satish51392111
22 Replies

5. Solaris

Cron jobs and at jobs

There are two jobs in Solaris , Cron and at jobs.. I know how to disable or enable cron jobs. How can I enable at jobs and disable it. Kindly help. Rj (2 Replies)
Discussion started by: jegaraman
2 Replies

6. Shell Programming and Scripting

fetching Month end using cal

Hi , Can someone please assist to get monthend using cal utility and monthend shouldn't be saturday or sunday. Cheers, gehlnar (2 Replies)
Discussion started by: gehlnar
2 Replies

7. UNIX for Advanced & Expert Users

last month end date

Hi, How to get the lastmonth's end date? (have current date) through s shell script. I need to get it and pass it to a procedure. Please advice. Thanks in advance. (7 Replies)
Discussion started by: vanathi
7 Replies

8. UNIX for Dummies Questions & Answers

setting up cron job for month end week report

Hi all, Needs your help in scheduling a cron job for the below mentioned requirement. Just let me know if anybody has a similar job running as mentioned below: Month end reports - Report of all items created in a parent table that were created during the week. Presently this report runs... (3 Replies)
Discussion started by: Bhups
3 Replies

9. UNIX for Advanced & Expert Users

Unix Cron Month End Processing

Is it possible to use cron to schedule a job that will run the first 3 Sunday's during a month in addition to the last day of the month? (3 Replies)
Discussion started by: cpete
3 Replies

10. UNIX for Dummies Questions & Answers

Cron Jobs

Where can someone find info on Cron Jobs? Very new to UNIX and the PC I inherited looks to have several of them. Looks like they are some kind of background program that runs automatically at specified times. Would like to delete some of them and know more about them. (6 Replies)
Discussion started by: dereckbc
6 Replies
Login or Register to Ask a Question