Timestamp format in HP-UX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Timestamp format in HP-UX
# 1  
Old 06-14-2018
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.
This User Gave Thanks to nickz2017 For This Post:
# 2  
Old 06-14-2018
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
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 06-14-2018
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 {} +

These 3 Users Gave Thanks to MadeInGermany For This Post:
# 4  
Old 06-14-2018
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.

# 5  
Old 06-14-2018
Code:
# is now
foreach $argfile (@
ARGV) {

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

# 6  
Old 06-14-2018
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert date in dd mm yyyy format to UNIX timestamp

Hello All, I have a date in DD/MM/YYYY format. I am trying to convert this into unix timestamp. I have tried following: date -d $mydate +%s where mydate = 23/12/2016 00:00:00 I am getting following error: date: extra operand `+%s' Try `date --help' for more information. ... (1 Reply)
Discussion started by: angshuman
1 Replies

2. Shell Programming and Scripting

Convert UNIX timestamp to readable format in the file

Hello I have a file : file1.txt with the below contents : 237176 test1 test2 1442149024 237138 test3 test4 1442121300 237171 test5 test7 1442112823 237145 test9 test10 1442109600 In the above file fourth field represents the timestamp in Unix format. I found a command which converts... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

Getting file timestamp in certain format

Hi all, I'm a Unix newbie and I need to get file timestamp in the following format: YYYYMMDD HH24:MM:SS example: 20120713 18:49:30 For start I've tried the following code, but I don't know how to display the year and even format the date: ls -l $filename | awk '{print $7 $6 $8}' My... (4 Replies)
Discussion started by: Braun
4 Replies

4. UNIX for Dummies Questions & Answers

Format/Fix Timestamp Data in a File.

Hello Experts, I have a timestamp(6) column in a .csv data file , format of the data is as below:- ETCT,P,Elec, Inc.,abc,11/5/2010 4:16:09.000000 PM,Y,Y,Y I want the timestamp column to be properly formatted like 11/05/2010 04:16:09.000000 PM Currently the "0" is missing with... (3 Replies)
Discussion started by: mtlrsk
3 Replies

5. AIX

Convert unix timestamp to year month day format ?

Hello, How do I convert unix timestamp value to 'normal' date format - to get year month and day values ? Looks like it's easy to do using GNU date (linux systems). But how do I do tthis on AIX ? I don't want to write C program, any ways to do that using unix shells ? thanks (1 Reply)
Discussion started by: vilius
1 Replies

6. Shell Programming and Scripting

To convert a date(in string format) to unix timestamp

Hi All, I have a string like below. "Mar 31 2009" . I want to convert this to unix time . Also please let me know how to find the unix time for the above string minus one day. For Eg. if i have string "Mar 31 2009" i want to find the unix time stamp of "Mar 30 2009". Thanks in advance,... (11 Replies)
Discussion started by: girish.raos
11 Replies

7. UNIX for Advanced & Expert Users

ls -l timestamp display format

The time stamp format using "ls -l" is either mmm dd hh:mm or mmm dd yyyy. For later case, how can I know the hh:mm as well. Thanks. (3 Replies)
Discussion started by: pok.fung
3 Replies

8. Programming

converting unix timestamp into readable format using c++

hi everyone, im new here and am in desperate need of help. I want to convert my 32 bit unix time stamp ' 45d732f6' into a readable format (Sat, 17 February 2007 16:53:10 UTC) using c++. I have looked around the interent but i just cant make sense of anything. All examples i can find just... (3 Replies)
Discussion started by: uselessprog
3 Replies

9. UNIX for Advanced & Expert Users

get the timestamp of a file in desired format

Hi, I have a file say abc. I get the timestamp in following way: ls -ltr abc | awk -F" " '{print $6,$7,$8}' Mar 8 10:23 I need to get the timestamp as : 03-08-2007 10:23:00 Thanks Sumeet (1 Reply)
Discussion started by: sumeet
1 Replies

10. Shell Programming and Scripting

how to convert from timestamp to date format in tcsh

hello all im looking for fast way to convert timestamp format to date format and vaiseversa in tcsh , can it be done? thanks allot (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question