date command issue from crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date command issue from crontab
# 1  
Old 05-28-2010
Java date command issue from crontab

Hi Expert,

I am using TZ for extracting yesterday date and day before yesterday date
example :

Code:
date_yes=`TZ="GMT+28" date +'%d-%b-%Y'`
date_dbyes=`TZ="GMT+48" date +'%d-%b-%Y'`
 
echo $date_yes $date_dbyes
 
26-May-2010  27-May-2010

I have written a small script for the same named as test.sh

when i ran the script it will give me correct result. Issue is i schduled this script in crontab (it will run for everyday at 1 a.m )

Code:
00 01 * * * sh test.sh

But i am getting 25-May-2010 26-May-2010 in two variables, i am stuck for the day. I am looking into this for last 4 hours.

Please help me out.

Last edited by Scott; 06-01-2010 at 07:55 PM.. Reason: Code tags, PLEASE!
# 2  
Old 06-01-2010
Mumbai time is UTC/GMT plus 5:30.
01:00 in Mumbai is 19:30 Greenwich Mean Time (GMT) "yesterday".

Assuming that your cron runs in Mumbai Time the definition of "yesterday" and "day-before-yesterday" when expressed in Greenwich Mean Time (GMT) changes according to the time parameter of the crontab entry.

I don't think that changing the TZ variable in this manner is a valid technique outside of the GMT timezone. You need to be working in the same timezone as cron.

Depending on what Operating System and Shell you have there are published techniques for date arithmetic for non-GMT timezones.

Alternatively you could test the cron every hour for 24 hours and use this information to work out a simple adjustment.

Afterthought. You could create a cron for 00:01 to create a file for "today" and age the file daily to produce "yesterday" and "day-before-yesterday". With forward planning you will have all the reference dates available after three days. The content of each file can be the output from "date" in whatever format you require. This will be a lot less hassle than date arithmetic.

Last edited by methyl; 06-01-2010 at 08:27 PM.. Reason: afterthought
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Crontab Issue

My colleague who was a sysadmin , has created a cron job script which collects logs and process them. The script works perfectly as per the defined time set by him. it works when we keep the timing as 55 05 * * * , whereas if we try to prepone the cron task is not getting executed. Where... (10 Replies)
Discussion started by: aravindj80
10 Replies

2. Shell Programming and Scripting

Crontab issue

hi, i have schduled a job through crontab, but it is not getting executed. bash-3.2$ crontab -l # Monthly Download (mm hh DD MM format) 35 05 01 04 * /home/ftpsrp/srpftp1/download/ofrdb/scripts/load_ofrdb.sh crr.sh here is the permission of the .sh files -rwxr--r-- 1 ftpsrp srp ... (7 Replies)
Discussion started by: lovelysethii
7 Replies

3. Solaris

Solaris 9 Zone : Date command in crontab shows delayed(One Hour) output

SOLARIS 9 Zone : date command in crontab shows delayed(One Hour) output Hi folks, the date command shows the correct date and time, How ever, if the date command executed through crontab in any form of scrip the output shows as one hour delayed, similar to date -u.. Can some one help in... (12 Replies)
Discussion started by: judi
12 Replies

4. UNIX for Advanced & Expert Users

Crontab issue

We have configured a script to be run at specific time using crontab. # crontab -l 15 11 * * * VM_Count_V4.shas per the crontab entry script should run every day 11.15 a.m Every time when the script is executed i get a mail but when i run it using crontab it doesn't send any mail. However... (1 Reply)
Discussion started by: pinga123
1 Replies

5. Shell Programming and Scripting

Issue with crontab

I have a ksh script which will connect to a database and executes some sql scripts. If i run the ksh script it is working fine. But if i schedule it to run at a perticular time using cron the sql script is not running. The scriptl initially creates a spool file for sql script and then connects and... (12 Replies)
Discussion started by: Sriranga
12 Replies

6. Shell Programming and Scripting

date command issue from crontab

Hello Experts, I am facing problem in date command with TZ test.sh Output : 26-May-2010 27-May-2010 I scheduled this script everyday at 1 a.m 00 01 * * * sh test.sh when i was called this script test.sh from crontab , it was giving me other output (1 Reply)
Discussion started by: pritish.sas
1 Replies

7. Shell Programming and Scripting

crontab issue

Helo . I have 2.6.13-1.1526_FC4smp here. I am trying to make crontab execute my simple shell script, but noting happens. here is how i am testing this : $ pwd /home/oracle $ ls -l two* ls: two*: No such file or directory $ $ crontab -e crontab: installing new crontab $ $ crontab... (7 Replies)
Discussion started by: tonijel
7 Replies

8. UNIX for Dummies Questions & Answers

getting the date in crontab command

Hi All, There is a requirement to create a file everyday using the cronjob with the date as its name. any suggestions for the crontab command that'll serve this purpose? e.g. 02 30 * * * touch abcd.`date +%d.%m.%y` needless to say.. this doesn't work.. looking fwd to lots of... (7 Replies)
Discussion started by: pranavagarwal
7 Replies

9. UNIX for Advanced & Expert Users

date issue-find prevoius date in a patricular format

Hi , I have written a shell script that takes the current date on the server and stores it in a file. echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in... (3 Replies)
Discussion started by: bsandeep_80
3 Replies

10. UNIX for Dummies Questions & Answers

Crontab Issue

I have a backup script that is suppose to run every night of the week, but it never does, it starts to run. The way I can tell is that the dates on dump_log are changing to when the script runs. If I look in the cron log file is shows ! > root 506342 cr /etc/back_up Fri Aug 5 10:30:00... (2 Replies)
Discussion started by: rickyt00
2 Replies
Login or Register to Ask a Question