Unix/Linux Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Timestamp format in HP-UX

UNIX for Advanced & Expert Users


Tags
hpux, ls, timestamp

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
nickz2017's Unix or Linux Image
nickz2017 nickz2017 is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 14 June 2018, 7:24 PM EDT
Posts: 3
Thanks: 2
Thanked 1 Time in 1 Post
Unix or Linux Question Timestamp format in HP-UX

I am on HP-UX B.11.11 OS. My requirement is to display a list of directories (not files) and the last modified time format should be DD-MON-YYYY HH:MI:SS AM/PM. I am able to get the list using either

Code:
   ls -lF | grep /

OR

Code:
   ls -ld -- */

but I am unable to set the time format as I want. The --full-time parameter doesn't work in HP-UX, and HP-UX doesn't have stat as well.

Questions:

1. I can try with Perl (located at /usr/bin/perl) but I am not very well versed with it. Could anyone please provide me a script to get the same output as that of ls -ld */

2. Is there any other way to display this information without using C or Perl, by just using standard commands and parameters?

3. I was wondering how is WinSCP able to display the full date/time format in the UI ? Anyone knows what command it uses internally to display the directory contents in the UI?

Any help is appreciated.
The Following User Says Thank You to nickz2017 For This Useful Post:
samuelCan (2 Days Ago)
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 21 June 2018, 9:53 AM EDT
Location: Lancashire, UK
Posts: 3,559
Thanks: 1,566
Thanked 699 Times in 627 Posts
You would be best looking at the stat command to get the information you want in the format you want. The output of ls is slightly fickle. If a file is older than 6 months it may display a day/month/year rather than a day.month/time which might confused your process.

Using stat and the appropriate flags, you can build the time in a suitably portable way.

Have a go and let us know if you get stuck and we will try to help you.




Kind regards,
Robin
The Following User Says Thank You to rbatte1 For This Useful Post:
nickz2017 (1 Week Ago)
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 June 2018, 5:13 AM EDT
Location: Simplicity
Posts: 4,124
Thanks: 359
Thanked 1,402 Times in 1,259 Posts
SysV-derived Unix does not have a stat command. Only the latest Solaris 11 has got it.
I would try perl.


Code:
man perl

leads to


Code:
man perlfunc

for the stat() and localtime() functions.
I pasted the examples, and with a little trial and error I got


Code:
#!/usr/bin/perl
foreach $argfile (@ARGV) {
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks) = stat($argfile);
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
    printf "%s-%02d-%02d %02d:%02d:%02d %s\n", 
        $year+1900, $mon+1, $mday, $hour, $min, $sec, $argfile;
}

Now you can make it executable and run it with


Code:
/path/to/perlscript */
find . -type d -exec /path/to/perlscript {} +

The Following 3 Users Say Thank You to MadeInGermany For This Useful Post:
jim mcnamara (1 Week Ago), nickz2017 (1 Week Ago), samuelCan (2 Days Ago)
    #4  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
nickz2017's Unix or Linux Image
nickz2017 nickz2017 is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 14 June 2018, 7:24 PM EDT
Posts: 3
Thanks: 2
Thanked 1 Time in 1 Post
Thanks for looking into it. I executed the script you provided but ended up with some errors. It might be a formatting error from my side, since I am pretty new to Unix/Perl. This is what I got:



Code:
$ /usr/bin/perl
foreach $argfile (@
ARGV) {
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks) = stat($argfile);
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
    printf "%s-%02d-%02d %02d:%02d:%02d %s\n",
        $year+1900, $mon+1, $mday, $hour, $min, $sec, $argfile;
}
syntax error at - line 1, near "ARGV) "
syntax error at - line 7, near "}"
Execution of - aborted due to compilation errors.

Sponsored Links
    #5  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 21 June 2018, 9:11 PM EDT
Location: NM
Posts: 11,416
Thanks: 629
Thanked 1,170 Times in 1,077 Posts


Code:
# is now
foreach $argfile (@
ARGV) {

# should be
foreach $argfile (@ARGV) {
# no line feeds

Sponsored Links
    #6  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nickz2017
nickz2017's Unix or Linux Image
nickz2017 nickz2017 is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 14 June 2018, 7:24 PM EDT
Posts: 3
Thanks: 2
Thanked 1 Time in 1 Post
Thanks @rbatte1 and @MadeInGermany

I posted the question in Unix StackExchange as well, and found the solution. I have posted the final script there in case it's helpful for others with same issue/question.

I am unable to paste the web link to the StackExchange thread here since I guess I have to have at least 5 posts, which I don't. I wish I was able to provide the link so that it would have been helpful to others stumbling on the post in future.

---------- Post updated at 06:24 PM ---------- Previous update was at 06:23 PM ----------

Thanks @rbatte1 for your help as well, but unfortunately even stat is not available in HP-UX version we have.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting file timestamp in certain format Braun Shell Programming and Scripting 4 07-13-2012 04:31 PM
Format/Fix Timestamp Data in a File. mtlrsk UNIX for Dummies Questions & Answers 3 01-08-2011 09:50 AM
ls -l timestamp display format pok.fung UNIX for Advanced & Expert Users 3 08-11-2009 02:22 PM
converting unix timestamp into readable format using c++ uselessprog Programming 3 04-07-2008 03:07 PM
get the timestamp of a file in desired format sumeet UNIX for Advanced & Expert Users 1 03-08-2007 11:24 AM



All times are GMT -4. The time now is 05:31 AM.