LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash processing tips needed for listing passwordless users. (http://www.linuxquestions.org/questions/linux-software-2/bash-processing-tips-needed-for-listing-passwordless-users-725987/)

green_dood 05-14-2009 11:10 AM

Bash processing tips needed for listing passwordless users.
 
Hi there guys:

I was asked to list passwordless or locked accounts in a fedora system. As far as I know, fedora or RH dont allow passwordless accounts (the system locks the account Edit: ... unless you set passwd -d :-P ), so I might show info about locked accounts.


I am totally aware that I could do a grep or an awk searching for "!!" or "", but my people is asking me to check against passwd -S (which prints info of accounts). The thing, is that in Solaris you can check with passwd -a -s all the users, but in Linux I couldnt find anything similar.

The question here is what approach do you reccomend for passing, say , the list of users ( like the output of awk searching only user names) to the command passwd -S one by one?

Any comments?

Thanks for your support!

eco 05-14-2009 11:19 AM

a 'man passwd' gave me:

# passwd -aS

Oups, hit enter a bit too quick...

a = all,

You should be able to work it out from there ;)

green_dood 05-14-2009 12:03 PM

Quote:

Originally Posted by eco (Post 3540759)
a 'man passwd' gave me:

# passwd -aS

Oups, hit enter a bit too quick...

a = all,

You should be able to work it out from there ;)

[root@satellite ~]# passwd -aS
passwd: bad argument -aS: unknown option


Sorry, tried it before (I even used passwd -a -S ). Which version of fedora are you using? Mine is Fedora 11

eco 05-14-2009 04:54 PM

I am running Kubuntu with the password binary version 4.1.1

Code:

$ dpkg -l|grep passwd
ii  base-passwd                                3.5.21                                  Debian base system master password and group
ii  kdepasswd                                  4:4.2.2-0ubuntu4                        password changer for KDE 4
ii  passwd                                    1:4.1.1-6ubuntu6                        change and administer password and group dat

what does the man page say? Maybe you have an older version but I'm sure you could loop through the passwd file and check them individually with the 'passwd -S' command

green_dood 05-15-2009 12:13 PM

Solved :-)
 
Yep, I needed to run a little script to first get all the users and then pass them to passwd -s

Code:

USERS="$(cut -d: -f 1 /etc/passwd)"
for u in $USERS
do
passwd -S $u | grep -Ew "NP" > /dev/null
if [ $? -eq 0 ]; then
myUID=`awk -F":" "/$u/"'{ print $3}' /etc/group`
myGroups=`awk -F":" "/$myUID/"'{ print $1}' /etc/group`
echo Username: $u , UID: $myUID, GROUPS: $myGroups >>$reportFile
fi
done



All times are GMT -5. The time now is 08:27 AM.