- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Get the timestamp of a file on HP?
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
тАО09-10-2010 10:21 AM
тАО09-10-2010 10:21 AM
I want to write a shell script to get the modification timestamp of a file on HP. I cannot use C functions or Perl. The 'ls -l' command is not what I need. What I need is something like below:
START=$(date +%s)
But the 'date' has to be the modification time of a specific file.
Your response will be very helpful to me!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2010 10:39 AM
тАО09-10-2010 10:39 AM
Solution> I want to write a shell script to get the modification timestamp of a file on HP. I cannot use C functions or Perl.
Why oh why? You really want the 'stat()' function (which LINUX offers as a shell command but HP-UX doesn't).
# perl -le 'for (@ARGV) {print join " ",(stat($_))[9],$_}' file1 file2 ...
If you need to *compare* file modification timestamps you can use the Posix shell's: '-nt' and '-ot' file test operators for comparing newer ('-nt') and older ('-ot') as:
# [ ${file1} -nt ${file2} ] && echo "one newer than two"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2010 11:03 AM
тАО09-10-2010 11:03 AM
Re: Get the timestamp of a file on HP?
OK, I know of yet another potential solution for you. Look Dennis' response in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1320053
The salient code is thus:
# dumpmsg /usr/lib/nls/msg/C/ls.cat > /tmp/ls.msg
# vi /tmp/ls.msg
[ ...and replace lines 11 and 12 with:
%s
]
# gencat /tmp/ls.cat /tmp/ls.msg
# NLSPATH=%N.cat ls -l file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2010 01:00 PM
тАО09-10-2010 01:00 PM
Re: Get the timestamp of a file on HP?
Is the 'perl' command available to the base HP installation, just like the 'ls' command? I need to ensure my script works on all HP systems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2010 01:06 PM
тАО09-10-2010 01:06 PM
Re: Get the timestamp of a file on HP?
Is the 'perl' command available to the base HP installation, just like the 'ls' command? I need to ensure my script works on all HP systems.
Yes it is.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2010 06:28 PM
тАО09-10-2010 06:28 PM
Re: Get the timestamp of a file on HP?
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1320053
Actually Michelle wants the format where it is less than 6 months. (Or possibly HH:MM:SS.)
So what I had there was fine.
I'll ask that Michelle's duplicate be removed:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1447272
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2010 12:15 AM
тАО09-13-2010 12:15 AM
Re: Get the timestamp of a file on HP?
You already got good advice and solutions.
Please, please do not rely on timestamps in Unix AT ALL. I am not sure what your goal
is, but timestamps are easy to forge.
Let me demonstrate (this is actually part
of my presentation I did when I was teaching
HP-UX junior support team at a large hospital
recently):
# ls -l /etc/motd
-rw------- 1 root sys 842 Jul 16 2008 /etc/motd
# NLSPATH=%N.cat ls -l /etc/motd
-rw------- 1 root sys 842 1216172154 /etc/motd
# perl -le 'for (@ARGV) {print join " ",(stat($_))[9],$_}' /etc/motd
1216172154 /etc/motd
Now, create a new file:
# touch -r /etc/motd /tmp/BLAH
... and its timestamps the timestamps:
# ls -l /tmp/BLAH
-rw------- 1 root sys 0 Jul 16 2008 /tmp/BLAH
# NLSPATH=%N.cat ls -l /tmp/BLAH
-rw------- 1 root sys 0 1216172154 /tmp/BLAH
# perl -le 'for (@ARGV) {print join " ",(stat($_))[9],$_}' /tmp/BLAH
1216172154 /tmp/BLAH
Good luck and if you are doing these checks
for security audits, you need tools
like Tripwire, AIDE, and so on.
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2010 01:33 AM
тАО09-13-2010 01:33 AM
Re: Get the timestamp of a file on HP?
# NLSPATH=%N.cat ls -l /etc/motd
-rw------- 1 root sys 842 1216172154 /etc/motd
Are you sure this command out ? in my environment I got this:
# ls -l /etc/motd
-rw-rw-rw- 1 root sys 210 Oct 27 2009 /etc/motd
# NLSPATH=%N.cat ls -l /etc/motd
-rw-rw-rw- 1 root sys 210 Oct 27 2009 /etc/motd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2010 03:55 AM
тАО09-13-2010 03:55 AM
Re: Get the timestamp of a file on HP?
> Hakki: Are you sure this command out ?
Re-read my comments. You need to create a modified message catalog.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2010 05:32 AM
тАО09-13-2010 05:32 AM
Re: Get the timestamp of a file on HP?
Sorry I missed that, thank you for warning.
So, What do you say VK2COT 's infomation about time_stamp unreliability ?
I am totally surprised.