LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2009, 07:56 AM   #1
rhbegin
Member
 
Registered: Oct 2003
Location: Arkansas, NWA
Distribution: Fedora/CentOS/SL6
Posts: 381

Rep: Reputation: 23
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,
 
Old 11-11-2009, 08:20 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,808

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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

Last edited by pixellany; 11-11-2009 at 08:22 AM.
 
Old 11-11-2009, 08:24 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
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.

Last edited by druuna; 11-11-2009 at 08:55 AM.
 
Old 11-11-2009, 08:27 AM   #4
rhbegin
Member
 
Registered: Oct 2003
Location: Arkansas, NWA
Distribution: Fedora/CentOS/SL6
Posts: 381

Original Poster
Rep: Reputation: 23
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
 
Old 11-11-2009, 08:35 AM   #5
rhbegin
Member
 
Registered: Oct 2003
Location: Arkansas, NWA
Distribution: Fedora/CentOS/SL6
Posts: 381

Original Poster
Rep: Reputation: 23
Quote:
Originally Posted by druuna View Post
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.
Would I run this against the /etc/passwd or could I use
a file?
 
Old 11-11-2009, 08:55 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
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....
 
Old 11-11-2009, 09:32 AM   #7
rhbegin
Member
 
Registered: Oct 2003
Location: Arkansas, NWA
Distribution: Fedora/CentOS/SL6
Posts: 381

Original Poster
Rep: Reputation: 23
passwd -Sa | awk '( $2 == "LK" ) { print $1 }'
passwd: bad argument -Sa: unknown option
 
Old 11-11-2009, 10:48 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Code:
passwd -Sa | awk '( $2 == "L" ) { print $1 }'
fcron
lp
smmsp
messagebus
stunnel
apache
slapd
mysql
proftpd
sshd
 
Old 11-11-2009, 12:55 PM   #9
rhbegin
Member
 
Registered: Oct 2003
Location: Arkansas, NWA
Distribution: Fedora/CentOS/SL6
Posts: 381

Original Poster
Rep: Reputation: 23
Thank you for your help, I was not familiar with passwd -S user
to display it being locked.

Thanks again!

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to compare two files swatward Linux - Newbie 17 04-18-2012 06:14 PM
bash script: compare two group list Dr_Death_UAE Linux - General 7 09-03-2009 07:32 AM
Want to compare strings in bash script IsharaComix Programming 6 10-28-2008 08:49 PM
need help with bash script to compare file sizes rimvydazas Programming 3 04-03-2008 06:18 AM
Bash script to compare dir contents Boffy Programming 2 08-02-2005 06:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration