Cron for end of month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron for end of month
# 8  
Old 06-02-2012
I would have done it this way:

Code:
if awk -v date="$(date "+%Y %m %d" )" '
    BEGIN {
        split( date, dt, " " );
        split( "1 -2 1 0 1 0 1 1 0 1 0 1", dim, " " );                                  # days in month; sort of
        dim[2] += dt[1]%4 != 0 ? 0 : (dt[1]%100 != 0 ? 1 : (dt[1]%400 != 0 ? 0 : 1));   # adjust for leap year

        exit( !( dt[3] == dim[dt[2]] + 30) );       #true if last day, invert because for shell, exit code 0 is success 
    }
'
then
    echo "last day"    # put your logic to remove files here
else
    echo "not last day"
fi



You can test (regardless of day) by replacing the initial if expression with something like the line below which has the date hard coded:

Code:
if awk -v date="2012 06 30" '

This User Gave Thanks to agama For This Post:
# 9  
Old 06-03-2012
Quote:
Originally Posted by user`
Hi, just wanted to give updates regarding the end of month script. I tried Chubler_XL codes and unfortunately it didn't work. I was waiting for 05/31.

This is what i have tried:

Code:
59 23 * * * /home/user/eomt.sh >/dev/null 2>&1

eomt.sh:

Code:
#!/bin/sh
 
if [ `date +%d` -eq `awk '$NF{E=$NF} END{printf E}'` ]
then
    rm /home/user/tst/logs/* && rm /home/user/tst/stats/*
fi
exit 0

I also tried to run the script manually by using ./eomt.sh and it doesn't even come out.

best regards
user
Oops something seems to be missing here try:

Code:
#!/bin/sh
 
if [ `date +%d` -eq `cal | awk '$NF{E=$NF} END{printf E}'` ]
then
    rm /home/user/tst/logs/* && rm /home/user/tst/stats/*
fi
exit 0

These 2 Users Gave Thanks to Chubler_XL For This Post:
# 10  
Old 06-04-2012
agama, Chubler_XL , thanks so much. I'll try this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

cron job to run on second to last friday each month

I needed a cron job to run on the second to last friday of every month. Our servers are running HP-UX, and the HP-UX date command is pretty basic and does not have all of the fancy options that Linux date command does, and it does not have the ability at all to return future dates. So I had to... (0 Replies)
Discussion started by: lupin..the..3rd
0 Replies

3. Shell Programming and Scripting

Displaying time left to end of day, week, month?

Hello, basically I'm looking after a way of showing how many time is left to the end the day, week, month... I can't seem to figure this out, so could one of you skilled guys tell me how should this be approached? Examples: Time left: Day: 12h 12m 11s Week: 4d 12h 12m 11s Month:... (4 Replies)
Discussion started by: TehOne
4 Replies

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

5. Shell Programming and Scripting

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... 02 16 * * * && /home/user/job-eom.kshI also need to be able to run a... (2 Replies)
Discussion started by: jthompson333
2 Replies

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

7. UNIX for Dummies Questions & Answers

Cron job -- to execute at every first Sunday of every month

Dear all How can I schedule the cronjob to be run sometime at every first Sunday at every month? I have the edit the cronjob every month now, thanks (2 Replies)
Discussion started by: shanemcmahon
2 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. Shell Programming and Scripting

Cron to schedule 1st Wednesday of every Month??

Is there a way to use cron to run a job on the 1st Wednesday of every month?? The more generic question is, "Are all of the fields in crontab AND'd together or are some OR'd?". i.e. I had an entry in my crontab this morning as follows and I didn't expect it to run since the day of month is 20... (5 Replies)
Discussion started by: bradtri
5 Replies
Login or Register to Ask a Question