time arthemetic - really urgent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting time arthemetic - really urgent
# 1  
Old 01-22-2007
time arthemetic - really urgent

guys.. i currently use this logic to calculate date and time.

Code:
export day=`date +%d`
export month=`date +%m`
export day_len=${#day}
export mon_len=${#month}
export hr_min=0000
if [[ $day_len -lt 2 ]] || [[ $mon_len -lt 2 ]] 
then
   month=0$month
   day=0$day   
   export time_search=$month$day$hr_min
else 
   export time_search=$month$day$hr_min
fi

this basically sets the date and time to 12 midnight each day. I basically use this to set up a grep command like this

Code:
touch  -t $time_search dummy
       ecust_time_stamp=$(find .  -name 'eCustomerCME*' -newer dummy  -type f  -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ')

I want my $time_search variable to be set (currrent time - 2 hrs) each time the grep statement is executed as a part of the code. Can you please suggest me how to do this.

Thanks in advance.
# 2  
Old 01-22-2007
sample script:

date
TZ=GMT+3 date
TZ=GMT-6 date
TZ=GMT+9 date
TZ=GMT-12 date


Output:

Mon Jan 22 16:32:27 CET 2007
Mon Jan 22 12:32:27 GMT 2007
Mon Jan 22 21:32:27 GMT 2007
Mon Jan 22 06:32:27 GMT 2007
Tue Jan 23 03:32:27 GMT 2007


Proper value for TZ=....... depends on your timezone
# 3  
Old 01-22-2007
thanks for the reply. i want my output to ne like this

date = 23
month = 01
hr = 08
minutes = 46.

i will have to modify my code to get (current time - 2hrs).

thanks
# 4  
Old 01-22-2007
The touch command will assume the current year unless you specify it. So your script will fail in the first hours of a year. The full timestamp for touch is yyyymmddhhmm.ss and it is no problem to specify the whole thing. Recall that 2 hours is 7200 seconds. With perl you can get the stampstamp of two hours ago like this:
$ perl -e '@d=localtime time()-7200; printf "%4d%02d%02d%02d%02d.%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]'
200701220915.14
$
# 5  
Old 01-22-2007
Sample script:

TIME_SEARCH=`TZ=GMT+3 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT-6 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT+9 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT-12 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT+15 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT-18 date +%m%d%H%M`
echo $TIME_SEARCH
TIME_SEARCH=`TZ=GMT+21 date +%m%d%H%M`
echo $TIME_SEARCH

Output:

01221357
01222257
01220757
01230457
01220157
01231057
01211957
# 6  
Old 01-22-2007
Thanks a lot fot your help guys. sb008.. i was able to do as you said.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

3. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

4. Solaris

how to execute java in specified time- urgent

Hi, 1. I want to execute a set of java files(a small appln) at specified time interval in solaris. that java uses documentum DFC calls. 2. How can i do this? from thread i chked ppl suggest to do cron, and so.. pls provide me a details steps hence i am new to solaris.. Any... (1 Reply)
Discussion started by: radhnki
1 Replies

5. UNIX for Advanced & Expert Users

urgent help needed!!in copying files to /tmp at boot time,pls help!

Hi all, I am trying to boot a an OS from RAM...(its a opensolaris based distro) For this i have picked up 2 key lib files that when copied to /tmp and mounted to respective places will do the job.. The sizes of these files combined comes upto 600mb.(i have 2gb ram) Now i have also located the... (0 Replies)
Discussion started by: wrapster
0 Replies

6. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies

7. UNIX for Advanced & Expert Users

URGENT,URGENT- Need help tape drive installation

Hi, I am trying to attach tape drive to sun V890 running Solaris 9 on it. I have installed HBA(qlogic) in slot 1 of 0-8 slots and booted the system. I do not see HBAin prtdiag output. The tape drive is not attached to HBA. The tape drive I am going to attach is Sony AIT3. 1.How can I make... (3 Replies)
Discussion started by: sriny
3 Replies

8. Shell Programming and Scripting

date arthemetic - really urgent

I get the timestamp of a file. the output of the timestamp is like this: Nov 3 11:04 I need to get the current date and subtract it from the timestamp. the output of the difference should be in minutes.. eg) (current_date-timestamp = x minutes) pls help guys.. thanks in advance (6 Replies)
Discussion started by: ragha81
6 Replies
Login or Register to Ask a Question