Re: script to find Paaswd age for all users (243 Views)
Reply
Regular Advisor
Ajin_1
Posts: 200
Registered: ‎06-09-2009
Message 1 of 3 (273 Views)

script to find Paaswd age for all users

Friends

 

I want a script to find the passwd age for all users in this server.

 

The script will give the output as following fields.

 

username uid passwd age

Thanks & Regards
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Honored Contributor
Horia Chirculescu
Posts: 829
Registered: ‎07-11-2009
Message 2 of 3 (243 Views)

Re: script to find Paaswd age for all users

Hello,

 

passwd -s <user>

 

would give some informations about the attributes related to some specific user. Read the passwd man page. You could write a script that will iterate passwd file in order to fin the users from your system and then call passwd -s on those names.

 

 

Best regards from Romania,
Horia.
Acclaimed Contributor
Dennis Handly
Posts: 25,058
Registered: ‎03-06-2006
Message 3 of 3 (226 Views)

Re: script to find passwd age for all users

[ Edited ]

>I want a script to find the passwd age for all users in this server.

 

Perhaps something like:

/usr/sbin/logins -x -a | awk '
BEGIN { print "Username   UID   passwd-reset" }
{
user = $1
uid = $2
getline; getline; getline
locked = $1
if (locked == "LK") {
   printf "%-8s %7s %s\n", user, uid, locked
} else {
   date = $2
   if (date == "000000") {
      printf "%-8s %7s %s\n", user, uid, "No expiration"
   } else {
      yy = "20" substr(date, 5, 2)
      mm = substr(date, 1, 2)
      dd = substr(date, 3, 2)
      printf "%-8s %7s %s-%s-%s + %s days\n", user, uid, yy, mm, dd, $4
   }
}
getline
}'

 

The user will have to do the date arithmetic to find the expiration date.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.