set date variable to 1 hr behind (233 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 7 (233 Views)
Accepted Solution

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
Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 2 of 7 (233 Views)

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
OldSchool
Posts: 3,372
Registered: ‎09-09-2004
Message 3 of 7 (233 Views)

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
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 4 of 7 (233 Views)

Re: set date variable to 1 hr behind

Thats great - thanks Peter.
hello
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 5 of 7 (233 Views)

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
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 6 of 7 (233 Views)

Re: set date variable to 1 hr behind

Chris,
no, as long as you do not export, the variable data stays within the script.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 7 of 7 (233 Views)

Re: set date variable to 1 hr behind

cheers fellas
hello
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.