Extract dates from /etc/shadow

694

Solution 1

There was an answer that got deleted, while somewhat wrong, did lead me in the correct direction.

Using gawk's strftime combined with some arithmetic gives me what I wanted.

cat shadow | gawk -F: '{ print $1 ":" strftime("%Y%m%d",86400*$3) ":" strftime("%Y%m%d",86400*$4)}'

root:20120304:19691231
daemon:20100203:19691231
bin:20100203:19691231
sys:20100203:19691231

Solution 2

chage -l <username>

Example Output:

Last password change                                    : Dec 17, 2015
Password expires                                        : Mar 16, 2016
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 7
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 14

Solution 3

for n in $(sudo cat /etc/shadow | awk '{FS=":";print $3}'); do date -d "01/01/1970 +${n}days" +%F; done 

To avoid the useless-use-of-cat-award:

for n in $(sudo awk '{FS=":";print $3}' /etc/shadow); do date -d "01/01/1970 +${n}days" +%F; done 

Solution 4

report password status on the named account passwd -S username

for user in $(cut -d: -f1 /etc/passwd); do sudo passwd -S $user; done

Solution 5

This outputs password update information for each user:

Read the /etc/passwd file >> parse each user >> run chage -l command on each user

for user in $(cut -d: -f1 /etc/passwd); do echo -e "\n $user \n" && chage -l $user; done
Share:
694

Related videos on Youtube

Mr. Boy
Author by

Mr. Boy

Updated on September 18, 2022

Comments

  • Mr. Boy
    Mr. Boy almost 2 years

    I have a multiset with a custom predicate function, e.g multiset<MyClass *,MyCompFunc> where MyCompFunc looks at an attribute on the MyClass objects. During the progress of the application, the objects might change in a way that should cause them to be reordered.

    What's the correct way to get the multiset to become reordered when this happens? Manually sort it, or remove the modified object, update it, and re-insert it?

    • Ken Simon
      Ken Simon almost 14 years
      I usually remove it and re-insert it, but I'm just going to put this as a comment instead of an answer, because I'm sure there's a better way.
    • Steve Jessop
      Steve Jessop almost 14 years
      I'm pretty sure you have to remove the object that's about to be modified, then modify it, then re-insert it. But I can't find a reference in the C++ spec right now that says you can't modify the Key of an entry in an associative container.
    • dirkgently
      dirkgently almost 14 years
      Maybe this is what Steve was referring to: The fundamental property of iterators of associative containers is that they iterate through the containers in the non-descending order of keys where non-descending is defined by the comparison that was used to construct them.
  • dribler
    dribler about 12 years
    +1 That would works, but not in my particular case. I am gathering information for all users, from a copy of the shadow restored to a temp folder from the backup, I was trying to track down some password changes to see if they are related to a system being potentially compromised.
  • Chris Alderson
    Chris Alderson over 7 years
    be nice and don't gawk at the cat gawk -F: '{ print $1 ":" strftime("%Y%m%d",86400*$3) ":" strftime("%Y%m%d",86400*$4)}' /etc/shadow
  • dribler
    dribler over 7 years
    @ChrisAlderson Meh, the UUOC people won't convince me. I find the cat file | filter | filter more readable, and sometimes when I am being lazy I will do it.