Monday, June 30, 2014

Change the number of days to date from /etc/shadow file


The file /etc/shadow has a couple date fields that are expressed as the number of days since Jan 1, 1970. Is there an easy way using to get a list of users and the calendar date of the last password change, and the expiration?

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


report password status on the named account passwd -S username
# for user in $(cut -d: -f1 /etc/passwd); do sudo passwd -S $user; done

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)}
20120304:19691231
daemon:20100203:19691231
bin:20100203:19691231
sys:20100203:19691231


http://unix.stackexchange.com/questions/36384/extract-dates-from-etc-shadow

No comments:

Post a Comment