[sllug-members]: Script Question

Jason Clint jason_clint at sento.com
Mon May 5 11:37:19 MDT 2008


Well I figured out you gave me a perfect enough solution something I
knew how to do but didn't think about.  Since the " File 2 =
nonusers.txt" is static I used this piece of code to just get a list of
what I needed:

cat /etc/passwd|grep -v /sbin/nologin|grep -v 0:0|grep -v 5:0|grep -v
6:0|grep -v 7:0 > somefile

Now I have a new file that has all the entries in it I want and none of
the entries I don't want.  I no longer have to maintain a static list I
just update the code if a new daemon is added or whatever.  I'm still
curios what this code is "[[:space:]]+2\
[[:space:]]" however.

Thanks for the help!

Junior Systems Administrator
Sento IT Jason Clint

(801) 431-9297
(801) 661-4139


-----Original Message-----
From: sllug-members-bounces at sllug.org
[mailto:sllug-members-bounces at sllug.org] On Behalf Of Jason Clint
Sent: Monday, May 05, 2008 11:16 AM
To: Roger Smith; sllug-members at sllug.org
Subject: RE: [sllug-members]: Script Question

I agree with roger the problem with diff is that the files may or may
not be in the same order.  I worked trying to use diff for a bit and it
requires a lot of trimming once you get the results.

Roger with this script you gave me it seems you define the files
"$file1=somefile", "$file2=someotherfile".  Then you go in and cat,
grep, sort and grep again all in one command.  First so I can understand
how this is done can you explain what this command does "[[:space:]]+2\
[[:space:]]" does that tell it to ignore the space?

Thanks.

Junior Systems Administrator
Sento IT Jason Clint

(801) 431-9297
(801) 661-4139


-----Original Message-----
From: Roger Smith [mailto:roger at itigger.com] 
Sent: Monday, May 05, 2008 10:51 AM
To: sllug-members at sllug.org
Cc: Jason Clint
Subject: Re: [sllug-members]: Script Question

On Monday 05 May 2008 10:44:37 am Jason Clint wrote:
> I am trying to do a Linux script to compare 2 files in some way and
only
> return a certain result.
>
> File 1 = /etc/passwd 
> File 2 = nonusers.txt
>
> File 2 has all the nonusers in it and I need to make sure my script
> doesn't accidently pull out any of them.  This is a for a manual ldap
> import and when I ran the script the first time I had a user named
"ns"
> so it pulled out "ns" and "nscd" which is a nonuser.  Anyway I was
> trying to use a script to compare the 2 and only return a result that
> didn't have "nologin" or even just return all results except the ones
> that were in the status list nonusers.txt.  I'm kind of new at shell
> scripting so any help would be greatly appreciated.

diff works, assuming the orders are the same. This is another way of
going 
about it.

# define files to compare
File1 = /etc/passwd 
File2 = nonusers.txt

# list all login entries : show unique entries and count how often they
# appear : show entries that appear once
cat $File1 $File2|grep -v nologin| sort |uniq -c|grep -E "[[:space:]]+1\
[[:space:]]"

# list all login entries : show unique entries and count how often they
# appear : only show entries that appear twice
cat $File1 $File2|grep -v nologin| sort |uniq -c|grep -E "[[:space:]]+2\
[[:space:]]"

-- Roger
______________________________________________________________________
See http://www.sllug.org/ for latest SLLUG news, information, links.
Join SLLUG and other UT LUG members on irc.FreeNode.net channel #Utah
sllug-members at sllug.org
http://www.sllug.org/cgi-bin/mailman/listinfo/sllug-members


More information about the sllug-members mailing list