Sponsored Content
Full Discussion: End of Month - Cron Jobs
Top Forums Shell Programming and Scripting End of Month - Cron Jobs Post 302281338 by cfajohnson on Wednesday 28th of January 2009 04:48:12 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

Cron Jobs

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

Name
       calendar - calendar reminder service

Syntax
       calendar [-]

Description
       The  command  consults the file `calendar' in the current directory and prints out lines that contain today's or tomorrow's date.  The com-
       mand recognizes most month-day dates, such as Dec. 7, december 7, 12/7, but it does not recognize dates formatted in the following ways:  7
       December  or  7/12.  If you give the month as * with a date, such as, * 1, that day in any month will do.  On weekends, specifying tomorrow
       extends through Monday.

       When an argument is present, the command searches through a user's calendar file in his login directory and sends him any positive  results
       by Normally this is done daily under control of

       The  calendar  file  is	first  run  through  the  C  preprocessor, to include any other calendar files specified with the #include syntax.
       Included calendars are shared by all users, and are maintained and documented by the local administration.

Options
       -    Functions for every user who has a calendar file in his login directory.

Restrictions
       The extended idea of tomorrow does not account for holidays.

Files
       calendar
       /usr/lib/calendar to figure out today's and tomorrow's dates
       /etc/passwd
       /tmp/cal*
       /lib/cpp, egrep, sed, mail as subprocesses

See Also
       at(1), cron(8), mail(1)

																       calendar(1)
All times are GMT -4. The time now is 04:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy