cannot set TZ for 2301 when time is 0001 (484 Views)
Reply
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 1 of 10 (484 Views)
Accepted Solution

cannot set TZ for 2301 when time is 0001

Hi,

I run a script that ftp's a file that was created with the previous hours time stamp by altering $TZ within the script:

cd $OUTDIR
OTZ=`echo $TZ`
TZ="GMT1BST"
FHOUR=`date +%H`
TFILE=`ls ${NFILE}_${DATE}_${FHOUR}*.csv`
TZ="$OTZ"

if [ -f ${OUTDIR}/${TFILE} ] ; then

continue

else

logfile "$TFILE is not available for transfer, please investigate and transfer the file."
exit 1
fi


echo "put $TFILE" >> $FTP
echo "$DATE:$TIME//Transfering $TFILE to $SERV " >> $PROGLOG
echo "!EOF" >> $FTP
chmod 777 $FTP

$FTP

if [ $? -ne 0 ] ; then

logfile "failed to FTP $TFILE to $SERV"
fi

The problem I have is at 00:01 when the script is excecuted it doesn't pick up the file for 2301 ....

any idea's please?

many thanks

Chris.

filename:

retail_20070109_2301.csv
hello
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

Hi:

Fiddling with the TZ variable to increment or decrement a time is doomed to failure.

Instead, use Perl to obtain the previous hour and minute:

# perl -e '($min,$sec)=(localtime(time()-60*60))[2,1];printf "%02d%02d\n",$min,$sec'

Regards!

...JRF...
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 3 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

love the termanology James ....

Ok thanks that's great however is there an awk alternative?

Many thanks.

Chris!
hello
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

Hi (again) Lawrenzo:

If you were to use the GNU 'awk' ('gawk') then you have some intrinsic timestamp functions available to you:

http://www.gnu.org/software/gawk/manual/gawk.html

See section 8.1.5 in the above link.

Regards!

...JRF...
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 5 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

I am still having an issue here because the file date I am trying to pick up is failing at 00:01.

I can manipulate the hour to go back to 2301 however I am having trouble getting the date to go back ....

how can I use perl to set the variable FDATE to display the previous day when the script is run at 0001?

Unfortunatly gawk is not installed across all our systems so that is not an option.

Thanks for any help.

Chris.
hello
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 6 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

I can manipulate the date in the following method:

OTZ=`echo $TZ`
TZ="GMT1BST"
FHOUR=`date +%H`
FDATE=`date +%Y%m%d`
TFILE=`ls ${NFILE}_${FDATE}_${FHOUR}*.csv`
TZ="$OTZ"

Thanks
hello
Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 7 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

Hi,
please study/adapt:

#!/usr/bin/sh
date
rm -f /tmp/x; touch /tmp/x
ar -r foo /tmp/x
timer=`tail -1 foo | awk -F' ' '{print $2}'`
echo $timer
echo "0d$timer=Y" | adb | tr -d '\011'
# Take off 1 day 3600 sec * 24
timer=`expr $timer - 86400`
echo $timer
echo "0d$timer=Y" | adb | tr -d '\011'

This is based on the epoche (secs since 1/1/1970). Output is:
$ ./b.sh
Thu Jan 18 12:27:59 GMT 2007
1169123279
2007 Jan 18 12:27:59
1169036879
2007 Jan 17 12:27:59

Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 8 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

ok thanks Peter I will give this a go.
hello
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 9 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

Hi (again) Lawrenzo:

> I can manipulate the hour to go back to 2301 however I am having trouble getting the date to go back ....how can I use perl to set the variable FDATE to display the previous day when the script is run at 0001?

We can add the year, month and day to our output quite easily and then you can snip the date and time components from it.

# perl -le '($year,$mon,$day,$hrs,$min)=(localtime(time()-$ARGV[0]))[5,4,3,2,1];printf "%04d%02d%02d:%02d%02d\n",$year+1900,$mon+1,$day,$hrs,$min' 3600

...will return the yyyymmdd:hhmm 3600-seconds (one hour) ago. You can pass any number of seconds earlier as the argument you need. For exactly 24-hours ago, the argument would be 86400 (of course).

Regards!

...JRF...
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 10 of 10 (484 Views)

Re: cannot set TZ for 2301 when time is 0001

ok thanks James,

Actually I have had a play with epoch time today and have learned something new.

I will study the world of perl next time I get a bit of time.

for now I will use your solution as I can uderstand what the command is doing and will be able to trouble shoot better.

Chris
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.