Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

script to find Paaswd age for all users

Ajin_1
Valued Contributor

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.
2 REPLIES
Highlighted
Horia Chirculescu
Honored Contributor

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.
Dennis Handly
Acclaimed Contributor

Re: script to find passwd age for all users

>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.