Shadow file

Hi,

In shadow file

smithj:Ep6mckrOLChF.:10063:0:99999:7:::
3rd Field 10063 indicates the number of days (since January 1, 1970) since the password was last changed.

I want to get the result with script the date on which the password was last changed in YYYY-MM-DD format.

can someone please help

Sorry I dont know well bash script and sed :stuck_out_tongue: but i think you can start from this:

$ chage --list [user] | sed -e '1!d' -e 's/^.*\: //'

change [user] with a true user and you can make a script that extract all users and a while loop for exec command for any user and another loop for change output in YYYY-MM-DD format.
.
I dont know if this is the better solution but I hope someone can help you better :wink:

bye :slight_smile:

not knowing your OS:

solaris: passwd -s smithj
linux: passwd -S smithj
aix: perl -e 'print scalar(localtime( `lsuser -a lastupdate smithj` ))'

use printf to format to your liking

smithj:Ep6mckrOLChF.:10063:0:99999:7:::

I think there is some misunderstanding.
I want to convert 10063 i.e 3rd field in shadow file from days format to date format of YYYY-MM-DD

Suppose the 3rd field is 365 then this should be converted to 12-31-1970
because 3rd Field indicates the number of days (since January 1, 1970)

like this?

$ date -d @1
output:
Thu Jan 1 01:00:01 CET 1970
You must convert days in seconds i think...

(Sorry...I dont know if there is a better solution :stuck_out_tongue: )

Can any expert please reply to this.

Appreciate it

Can someone help me how to do this using ksh.

$ date --date "Jan 1, 1970 + 365 days"
Fri Jan 1 00:00:00 CET 1971

...this is another way but i think you must search trough all options in date man pages...

ps: i dont use ksh

EDIT/ADD:
Anyway I suggest you to search with google something like: "epoch time converter" or "epoch date" and so on... you can find a lot of scripts :wink:

You don't state Operating System.
If you have the "logins" commands, the date of the last password change is available (albeit in MMYYDD format).
A script-readable format is:

logins -xto

Tip: Brand new accounts can look like dormant accounts until the first password expiry.