Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

set date variable to 1 hr behind

SOLVED
Go to Solution
Super Advisor Super Advisor

set date variable to 1 hr behind

Hello,

This problem is a bit tricky for me to work out:

NHOST=`hostname`
WKPATH=/sysadmin/scripts/performance
SAPATH=/sysadmin/logs/performance
FDATE=`date +%Y%m%d_%H%`


I am searching for a performance file that is created then renewed hourly by a different script - the script I run must search for the date an hour previously. I could use ls |tail |grep etc however I have many files in the performance directory and do not wish to put unnessasary load on the system:

is there a way I can get the correct file by minus 1hr?? ie:

The file is created every hour at the same time run by cron:

lobster99_20061218_1601.tmp is moved to
lobster99_20061218_1601.tmp at 1701

I need to take into account for the 24hr clock so at 00:01 i need to process the file 23:01.

how can this be done?

many thanks

Chris

hello
1 ACCEPTED SOLUTION
Honored Contributor Honored Contributor

Re: set date variable to 1 hr behind

Chris,
change the TZ variable within your script
For example:
#!/usr/bin/sh
date
otz=`echo $TZ`
TZ="GMT1BST"
date
TZ="$otz"
date

$ ./b.sh
Mon Dec 18 16:41:22 GMT 2006
Mon Dec 18 15:41:22 GMT 2006
Mon Dec 18 16:41:22 GMT 2006

6 REPLIES
Honored Contributor Honored Contributor

Re: set date variable to 1 hr behind

Chris,
change the TZ variable within your script
For example:
#!/usr/bin/sh
date
otz=`echo $TZ`
TZ="GMT1BST"
date
TZ="$otz"
date

$ ./b.sh
Mon Dec 18 16:41:22 GMT 2006
Mon Dec 18 15:41:22 GMT 2006
Mon Dec 18 16:41:22 GMT 2006

Honored Contributor Honored Contributor

Re: set date variable to 1 hr behind

Take a look at the post from spex regarding using "find" and "touch" to locate files


http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1037903
Super Advisor Super Advisor

Re: set date variable to 1 hr behind

Thats great - thanks Peter.
hello
Super Advisor Super Advisor

Re: set date variable to 1 hr behind

Thanks guys,

The find is an option I did consider.

Peter,

if I change the timezone within the script, doesnt that mean the system time changes even if for a moment?

Thanks
hello
Honored Contributor Honored Contributor

Re: set date variable to 1 hr behind

Chris,
no, as long as you do not export, the variable data stays within the script.
Highlighted
Super Advisor Super Advisor

Re: set date variable to 1 hr behind

cheers fellas
hello