I am using grep to parse the password file.
When I use
grep -w "avahi" /etc/passwd
I get two responses
avahi
and avahi-autoipd
I have not found a method to give me the unique response.
This command is part of a bigger script where the name (avahi
) is actually a variable.
This does work when the name is rpc
and rpcuser
. So I am guessing the it has something to do with the dash (-
) in the name.
Actual code:
#!/bin/ksh
getent shadow |cut -d: -f1-2|grep ':!!'| cut -d: -f1 > /tmp/pasck
while read line
do
NOLOGIN=`grep -w $line /etc/passwd | cut -d -f7|cut -d/ -f3`
if [[ $NOLOGIN != "nologin: && $NOLOGIN != "false" ]] ; then
echo "$line" "$NOLOGIN" >> /tmp/pasck.list
fi
done <?tmp/pasck
The script is trying to go through the shadow file and look for users with no passwords. Then I compare the results to the passwd file to find which of those accounts are set to /bin/false
or /sbin/nologin
. The remainder would be actual users with no password set but allowed on the system.
Keeping things simple - you could include colon that comes after the username in your
grep
statement: