- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- cannot set TZ for 2301 when time is 0001
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 12:10 AM
тАО01-09-2007 12:10 AM
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
Solved! Go to Solution.
- Tags:
- TZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 12:40 AM
тАО01-09-2007 12:40 AM
SolutionFiddling 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...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 12:43 AM
тАО01-09-2007 12:43 AM
Re: cannot set TZ for 2301 when time is 0001
Ok thanks that's great however is there an awk alternative?
Many thanks.
Chris!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 12:49 AM
тАО01-09-2007 12:49 AM
Re: cannot set TZ for 2301 when time is 0001
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...
- Tags:
- gawk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 10:50 PM
тАО01-17-2007 10:50 PM
Re: cannot set TZ for 2301 when time is 0001
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 11:10 PM
тАО01-17-2007 11:10 PM
Re: cannot set TZ for 2301 when time is 0001
OTZ=`echo $TZ`
TZ="GMT1BST"
FHOUR=`date +%H`
FDATE=`date +%Y%m%d`
TFILE=`ls ${NFILE}_${FDATE}_${FHOUR}*.csv`
TZ="$OTZ"
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 11:31 PM
тАО01-17-2007 11:31 PM
Re: cannot set TZ for 2301 when time is 0001
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 11:51 PM
тАО01-17-2007 11:51 PM
Re: cannot set TZ for 2301 when time is 0001
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2007 03:01 AM
тАО01-18-2007 03:01 AM
Re: cannot set TZ for 2301 when time is 0001
> 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2007 03:16 AM
тАО01-18-2007 03:16 AM
Re: cannot set TZ for 2301 when time is 0001
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