Need some help on bash script to compare /etc/passwd to locked users
I need some assistance with a bash script:
I want to read the /etc/passwd file with only the users and print out if it gets a match on the locked user file. What would be the best way to go about this? Read in all users, compare to locked users, and if it matches then print out all matched user names. Any help would be great. thanks, |
Here's a start:
Suppose that the "locked" file is also in /etc cd to /etc Code:
for user in $(sed 's/\:.*//' passwd);do grep -o $user locked;done |
Hi,
I'm not sure what it is you need to accomplish in the end, but the following command will show all locked users: passwd -Sa | awk '( $2 == "LK" )' The "LK" part could be "L", that depends on your system. Hope this helps. |
I actually took the users from the Server and just have the
user names in one file. The other file is from a database with only user names in which I was wondering would this work for these 2 files and only print out the ones that matched? thanks |
Quote:
a file? |
Hi,
The command shown will give you a list of users that are locked (to my knowledge /etc/passwd and /etc/shadow are used). If you need the users only, you need to extend the command: passwd -Sa | awk '( $2 == "LK" ) { print $1 }' PS: I made a typo in post #3: { should be ( and } should be ) Edited post #3.... |
passwd -Sa | awk '( $2 == "LK" ) { print $1 }'
passwd: bad argument -Sa: unknown option |
Code:
passwd -Sa | awk '( $2 == "L" ) { print $1 }' |
Thank you for your help, I was not familiar with passwd -S user
to display it being locked. Thanks again! :) |
All times are GMT -5. The time now is 04:33 AM. |