Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Timestamp and Comparing timestamp

Status
Not open for further replies.

annay121

Programmer
May 3, 2005
11
US
I am relatively new to shell scripting.

I would like to know how to read the timestamp of a given file present on
a) Unix m/c
b) FTP server
Also, how do i compare two timestamps that I have ?
 
A starting point in ksh with Perl:
file="/path/to/givenfile"
eval $(perl -e '
($ss,$mn,$hh,$dd,$mm,$yy,$wd,$yd,$dst)=localtime((stat("'$file'"))[9]);
printf("DATE=%04d%02d%02d\n",$yy+1900,$mm+1,$dd);
printf("TIME=%02d%02d%02d\n",$hh,$mn,$ss)')
echo "$file:"$DATE,$TIME

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV but I am not familiar with perl and looks like we have got an syntax error.When I run the script it says `(' unexpected.

I guess this code was for comparing timestamps (Pardon my foolishness but I have started to learn scripting only a couple of days back)

Also,will this work to get the timestamp from the FTP server ?
 
What shell are you using ?
The $(command) syntax is the same as `command`
For the FTP issue I'm afraid you have to parse the output of a DIR command.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I am using the Bourne shell.

How does the modtime <filename> work fo getting the timestamp from the FTP Server ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top