- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script, strange results
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
Forums
Discussions
Discussions
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
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
02-27-2003 07:14 AM
02-27-2003 07:14 AM
I???m using this script:
#!/bin/sh
for TIMESTAMP in $(cat /ser/tmp/timestamps.lst); do
DATE=$(perl -e 'print scalar localtime($TIMESTAMP)')
echo "The timestamp $TIMESTAMP is: $DATE"
done
This is the output:
The timestamp 1046289600 is: Wed Dec 31 18:00:00 1969
The timestamp 1046289300 is: Wed Dec 31 18:00:00 1969
The timestamp 1046289000 is: Wed Dec 31 18:00:00 1969
The timestamp 1046288700 is: Wed Dec 31 18:00:00 1969
The timestamp 1046288400 is: Wed Dec 31 18:00:00 1969
The timestamp 1046288100 is: Wed Dec 31 18:00:00 1969
And so on??? the output is always the same??? but if I run the command manually from the shell, I get the correct value.
Any idea about this behavior?
Thanks in advance for any hint!
Best regards
Rogelio
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:16 AM
02-27-2003 07:16 AM
Re: Script, strange results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:18 AM
02-27-2003 07:18 AM
Re: Script, strange results
#!/bin/sh
TIMESTAMP=" "
export TIMESTAMP
for TIMESTAMP in $(cat /ser/tmp/timestamps.lst); do
DATE=$(perl -e 'print scalar localtime($TIMESTAMP)')
echo "The timestamp $TIMESTAMP is: $DATE"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:27 AM
02-27-2003 07:27 AM
Re: Script, strange results
I tried both options, but the results are the same.
DATE=" "
export DATE
TIMESTAMP=" "
export TIMESTAMP
for TIMESTAMP in $(cat /ser/tmp/timestamps.lst); do
DATE=$(/usr/local/bin/perl -e 'print scalar localtime($TIMESTAMP)')
echo "The timestamp $TIMESTAMP is: $DATE"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:31 AM
02-27-2003 07:31 AM
Re: Script, strange results
Best regards
Rogelio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 07:33 AM
02-27-2003 07:33 AM
Re: Script, strange results
You must use double quotes instead of single quotes:
DATE=$(perl -e "print scalar localtime($TIMESTAMP)")
I think localtime() parameter is an unsigned integer. Using double quotes the parameter value for localtime() is the string '$TIMESTAMP' ( i.e, dolar capital T, capital I...) not the value of TIMESTAMP variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 11:59 PM
02-27-2003 11:59 PM
Re: Script, strange results
There is a problem with using a shell variable withing single quotes. enclosing in single quotes offers a performance benefit so that the shell does not pre-evaluate the strings as the shell interpreter should normally.
You may use however the eval command to ensure that the variables get pre-evaluated, in this manner.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/sh
for TIMESTAMP in $(cat /ser/tmp/timestamps.lst); do
DATE=$(eval "perl -e 'print scalar localtime($TIMESTAMP)'")
echo "The timestamp $TIMESTAMP is: $DATE"
done
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Just another way....
ramd.