The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
/etc/shells on /etc/passwd itik Linux 2 08-18-2009 09:40 PM
why we have different shells? shahnazurs UNIX for Advanced & Expert Users 2 12-17-2008 12:36 AM
pipes and shells isato UNIX for Dummies Questions & Answers 4 10-15-2008 12:15 PM
Shells dino_leix UNIX for Advanced & Expert Users 3 06-08-2005 07:07 AM
grep group and passwd file mozartny UNIX for Dummies Questions & Answers 4 07-17-2003 11:39 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2009
itik itik is offline
Registered User
  
 

Join Date: Oct 2007
Location: Toronto, Ontario
Posts: 354
cat /etc/passwd and grep -v on /etc/shells

Hi All,

I'd like to do this

cat /etc/passwd

and grep -v on the /etc/shells list

I'd like to find all shell that doesn't exist on the /etc/passwd.

Is there an easy way without doing a egrep -v "/bin/sh|/bin/bash................"?

How do I use a file /etc/shells as my list for search entries?

Thanks and more power.
  #2 (permalink)  
Old 08-21-2009
peterro peterro is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gresham, OR
Posts: 154

Code:
#!/bin/sh

for shell in $(</etc/shells)
do
  count=`grep -c $shell /etc/passwd`
  if [ $count -eq 0 ]
  then
    echo $shell not used in /etc/passwd
  fi
done

  #3 (permalink)  
Old 08-21-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 464
To give the file as input it is -f FILENAME in grep.

But am not sure whether it fits for your requirement or not!!


Code:
grep -v -f /etc/shells /etc/passwd

  #4 (permalink)  
Old 08-21-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
Try this:


Code:
awk 'NR==FNR{a[$NF];next} !($0 in a)'  FS=":" /etc/passwd FS="/" /etc/shells

  #5 (permalink)  
Old 08-21-2009
itik itik is offline
Registered User
  
 

Join Date: Oct 2007
Location: Toronto, Ontario
Posts: 354
Oohhh, I always ignore reading all these param......

This is what I want.

grep -v -f /etc/shells /etc/passwd

Thanks to ALL!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0