Cron to run first day of month to calculate date 3 months ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron to run first day of month to calculate date 3 months ago
# 1  
Old 05-17-2007
Cron to run first day of month to calculate date 3 months ago

Hi,

I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007).
i can get today's date by
Code:
'date +%Y%m%d`

is there a similar one liner or a few lines to achieve my result? would appreciate if anyone can shed some light. Thank you.
# 2  
Old 05-17-2007
sorry, found many similar threads in the forum.

because i am using GNU date, i can get it by
Code:
date -d " x months ago"

depending how many months i need, just replace x with the require number.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to get first & last day of a month from current date?

Hi, I need the first & last day of a month from any given date. For better understanding, if i need to back-fill data for date 07/20/2019 i.e July 20 2019, i need the first & last day has 07/01/2019 - 07/31/2019. FYI: I'm using GIT BASH terminal. sample code: export DT=$(date --date='6 days... (2 Replies)
Discussion started by: Rocky975583
2 Replies

2. Shell Programming and Scripting

Script to run on 2 4 and 7 day of the month

I am looking for a unix script which could run a job on 2, 4 and 7 working day of the month. if the days are falling on the saturday/sunday. it should run on the next day. Thank you.. (9 Replies)
Discussion started by: tradingspecial
9 Replies

3. Shell Programming and Scripting

Calculate given date - 1 day

Hi Team, We have a requirement as follows. If a date 20141220 as parameter to the script, then the script has to return the output as 20141219. i.e given date - 1. The requirement is simple. But it should satisfy leap year, the months having 31 and 30 days, the date in which day light... (9 Replies)
Discussion started by: kmanivan82
9 Replies

4. Shell Programming and Scripting

Cron to run 3rd Tuesday of every odd months

Hi, I need to schedule a script to run on the 3rd tuesday of every odd months at 9 am. min, hour would be - 0 9 month would be - 1,3,5,7,9,11 Can someone suggest how I can schedule it to 3rd tuesday? Thanks. (8 Replies)
Discussion started by: member2014
8 Replies

5. Shell Programming and Scripting

run the script for last day of the month

Hello Experts, I have a script which i want to run the on last day of every month. let say I have backup.sh script which i want to run it every month last day. Can anyone please help :confused: thanks (4 Replies)
Discussion started by: aks_1902
4 Replies

6. Shell Programming and Scripting

crontab entry to run every last day of the month

i've created a script which should run every last day of the month. what would be the exact crontab entry for this? thanks! (9 Replies)
Discussion started by: tads98
9 Replies

7. Shell Programming and Scripting

needs to display month for previous day date

Hello, I wanted to display the month for previous day date. Like, today date is 18-Nov-2008. So the previous date is 17-Nov-2008. The output should be November. If the today date is 1-DEC-2008, then output should be NOVEMBER. If the today date is 1-JAN-2008, then output should be DECEMBER.... (4 Replies)
Discussion started by: govindts
4 Replies

8. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

9. Shell Programming and Scripting

calculate 13 months ago

hi, I have a big file that contains datas since 4 years ago. I need re-create this file but just lines that are 13 months ago from today. see what I have: ( I have a file.ksh that calls this file.scl ok !!) ======== file.scl ================ /STATISTICS=stderr /STABLE /NODUPLICATES... (4 Replies)
Discussion started by: andrea_mussap
4 Replies

10. Shell Programming and Scripting

calculate 13 months ago

hi, I have a big file that contains datas since 4 years ago. I need re-create this file but just lines that are 13 months ago from today. see what I have: ( I have a file.ksh that calls this file.scl ok !!) ======== file.scl ================ /STATISTICS=stderr /STABLE /NODUPLICATES... (3 Replies)
Discussion started by: andrea_mussap
3 Replies
Login or Register to Ask a Question