Reputation: 11
I am looking to read the /etc/shadow file and strip out anything in the 2nd field that equal * or ! and anything in the 5th field not equal to 90 and then print out the 1st field, 5th field and 6th field and add the hostname at the end of each line and output it to a file. I am not sure what my best option is here....
example of /etc/shadow file
foo:$6$91s00atqlok0b861$7IJdhycBWBwipe82y6kaoXnAbwqhJNPyxXIiWzCFpb0um2aEquBKIaH5OAlGRAeua2F6jk6qQiicpC21aiTvt.:12345:7:90:7:30::
foofoo:!!:123456:0:90:7:::
foofoofoo:$6$5WSZ.Gde$RGkaObncaycypz9.wnerXauAPyIqyDQzh9cyUPuZ4LiNfRDGIS5DasngA5x51HPczH9NsE8mvkClIOs7a1K3p0:1234:0:99999:7:::
output
foofoofoo, 99999, 7, hostname
Field1=username
Field2=password
Field5=# days p/w needs to be changed
Field6=# of days to warn
much thanks
Upvotes: 0
Views: 109
Reputation: 4969
If you really want, you can do it in bash as well:
IFS=:
cat /etc/shadow |
while read f1 f2 f3 f4 f5 f6 f7 ; do
echo -n "$f1, $f5, $f6, "
hostname
done
Upvotes: 0
Reputation: 36
If I got your question correctly this is something you are looking for:
awk -v hostname=$(hostname) -F: '{ if ($2 != "*" && $2 != "!" && $5 == "90") { printf("%s %s %s %s\n", $1, $5, $6, hostname)}}' /etc/shadow >output
Upvotes: 2