Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

set date variable to 1 hr behind

SOLVED
Go to solution
Highlighted
lawrenzo_1
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
6 REPLIES
Peter Godron
Honored Contributor
Solution

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

OldSchool
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
lawrenzo_1
Super Advisor

Re: set date variable to 1 hr behind

Thats great - thanks Peter.
hello
lawrenzo_1
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
Peter Godron
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.
lawrenzo_1
Super Advisor

Re: set date variable to 1 hr behind

cheers fellas
hello