LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to list all locked account in linux? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-list-all-locked-account-in-linux-718736/)

robbiezr 04-13-2009 04:28 AM

how to list all locked account in linux?
 
how to list locked account in linux(redhat)?
I can use the command "passwd -S -username" to list a account who were locked .
who knows how to list all locked accounts with one command.

colucix 04-13-2009 06:51 AM

Code:

passwd -S -a | grep LK | cut -d " " -f1

ghostdog74 04-13-2009 07:01 AM

Code:

passwd -S -a |awk '/LK/{print $1}'

sundialsvcs 04-13-2009 07:46 AM

FYI...

Both of these illustrations demonstrate a very common technique that is used throughout Unix/Linux: what I'll call command piping.

In these examples, the output of one command (such as ls is "piped to" another command, which effectively filters its input and sends it down the line.

As the Perl folks like to say, "there's more than one way to do it." Both of these techniques work equally well.

robbiezr 04-13-2009 09:00 PM

Thanks for replying.
I tried the command below :

Code:

passwd -S -a | grep LK | cut -d " " -f1
Code:

passwd -S -a |awk '/LK/{print $1}'
but the system warns that "passwd: bad argument -a: unknown option".
I think there is no argument -a in this linux version.

I found that if a user is locked .there is a !! symbol in the row in the file /etc/shadow.

Code:

zr:!!$1$GDBXQuoJ$vnxddvimJCknM1P9HFz0v1:14347:0:99999:7:::

brycen 10-05-2009 12:34 PM

Under Debian at least the relevant string is "L" not "LK". So:

Code:

passwd -S -a | grep " L " | cut -d " " -f1
or

Code:

passwd -S -a | cut -d " " -f1-2 | grep "L$"

ccrmsc 09-19-2012 12:26 PM

I know this is an old thread but I came up with this solution for RHEL6.

cat /etc/passwd | cut -d : -f 1 | awk '{ system("passwd -S " $0) }'


All times are GMT -5. The time now is 10:34 AM.