Hi Friends,
I see the last login time as
time_last_login=1210762918
How to convert this to standard format.
I believe there is a command, I am not able to recollect it.
Thanks in advance
Hi Friends,
I see the last login time as
time_last_login=1210762918
How to convert this to standard format.
I believe there is a command, I am not able to recollect it.
Thanks in advance
if you have perl:
perl -e 'print scalar localtime(1210762918);'
Thanks Yogesh,
How to get the cursor to the next line..
aixtech2:/>perl -e 'print scalar localtime(1210762918);'
Wed May 14 07:31:58 2008aixtech2:/>
aixtech2:/>
Try adding the -l option -- perl -le 'print ...'
Thanks a lot Yogesh.....Actually i am trying to write a shell script to find out the user accounts that were not used for more than for 4 months (based on last login) ..and lock them.
DO you have anything simpler than this ..
sorry ..it is Era...:-}
If i write script like below:
lastlog1=`lsuser -a time_last_login root|awk -F= '{print $2}'`
echo $lastlog1
perl -le 'print scalar localtime($lastlog1);'
Output is :
1211381313
Wed Dec 31 20:30:00 1969
It is not taking the correct date/time..
If i give perl -le 'print scalar localtime(1211381313);' , then the output is correct...Wed May 21 11:18:33 2008.
Please help me ...how can i pass the value as a variable and get the correct output ...i need to process all user accounts..
Are you sure that it's the correct date? When I convert it my way, it give me:
GNU Awk 3.1.5
$ TZ=UTC awk 'BEGIN {print strftime("%Y-%m-%d %T", 1211381313)}'
> 2008-05-21 14:48:33
date (GNU coreutils) 5.97
$ date --utc --date "1970-01-01 1211381313 sec" "+%Y-%m-%d %T"
> 2008-05-21 14:48:33
You are not passing $lastlog1 to Perl correctly, so it's effectively doing localtime(0). (The date it prints is Jan 1 1970 UTC 00:00:00 converted to your local time zone.)
perl -le 'print scalar localtime(shift)' $lastlog1
If you are using awk anyway, the awk solution ripat posted would seem ideal.
lsuser -a time_last_login root|awk -F= '{print strftime("%Y-%m-%d %T",$2)}'
Just for the record: the problem is here:
You try to expand variable ($lastlog1) inside single quotes. To prevent special characters like "$" from being interpreted by the shell is exactly what single quotes have been invented for.
The line will probably work writing it that way:
perl -le 'print scalar localtime('"$lastlog1"');'
I hope this helps.
bakunin
do this.....
perl -le 'print scalar localtime('$a');'
and it returns
Wed May 21 07:48:33 2008