From: Ed Morton on
On 7/2/2010 12:12 PM, Janis Papanagnou wrote:
> On 02/07/10 19:00, Kush wrote:
>> On Jul 2, 12:01 pm, Ed Morton<mortons...(a)gmail.com> wrote:
>>> On 7/2/2010 10:22 AM, Kush wrote:
>>>
>>>
>>>
>>>
>>>
>>>> Hi folks.
>>>
>>>> I need to get the value of just the 'uid' from a line in /etc/exports.
>>>> For example, in the line below, I need to get the value '150', from
>>>> the 'anonuid=150' value, and I need to verify that that is a valid uid
>>>> by checking it against /etc/passwd:
>>>
>>>> /home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
>>>
>>>> I'm not very strong in sed/awk and all I can think of right now and I
>>>> have tried is:
>>>
>>>> cat /etc/exports | egrep /\.*/^/anonuid=
>>>
>>>> but that is not even giving me the string I want.
>>>
>>>> Any help will be greatly appreciated.
>>>
>>>> Kush
>>>
>>> This will get you the 150:
>>>
>>> $ cat file
>>> /home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
>>> $ awk '{sub(/.*,anonuid=/,"");sub(/,.*$/,"")}1' file
>>> 150
>>>
>>> If you show a sample of where you want to match it against in /etc/passwd we can
>>> expand on that.
>>>
>>> Ed.- Hide quoted text -
>>>
>>> - Show quoted text -
>>
>>
>> Ed. Thanks a lot for the quick reply.
>>
>> I want to compare this uid, ie 150 (or more if there are any more in
>> the /etc/exports) to the 3rd field in /etc/passwd file. If there is NO
>> match with the entries in /etc/passwd file then this uid needs to be
>> flagged.
>
> Untested...
>
> awk 'NR==FNR { sub(/.*,anonuid=/,""); sub(/,.*$/,""); a[$0]; next }
> $3 in a { delete a[$3] }
> END { for (id in a) print id }
> ' /etc/exports FS=: /etc/passwd

Looks familiar :-). I threw the "if" in there:

> NR==FNR { if (sub(/.*,anonuid=/,"")) { sub(/,.*$/,""); uids[$0] } next }

in case there's lines in /etc/exports that don't have ",anonuid=" in them, in
which case you'd end up with the uids array containg whetever's before the first
"," on those lines.

Ed.
From: Kush on
On Jul 2, 1:12 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:
> On 02/07/10 19:00, Kush wrote:
>
>
>
>
>
> > On Jul 2, 12:01 pm, Ed Morton <mortons...(a)gmail.com> wrote:
> >> On 7/2/2010 10:22 AM, Kush wrote:
>
> >>> Hi folks.
>
> >>> I need to get the value of just the 'uid' from a line in /etc/exports..
> >>> For example, in the line below, I need to get the value '150', from
> >>> the 'anonuid=150' value, and I need to verify that that is a valid uid
> >>> by checking it against /etc/passwd:
>
> >>> /home/joe       pc001(rw,all_squash,anonuid=150,anongid=100)
>
> >>> I'm not very strong in sed/awk and all I can think of right now and I
> >>> have tried is:
>
> >>> cat /etc/exports | egrep /\.*/^/anonuid=
>
> >>> but that is not even giving me the string I want.
>
> >>> Any help will be greatly appreciated.
>
> >>> Kush
>
> >> This will get you the 150:
>
> >> $ cat file
> >> /home/joe       pc001(rw,all_squash,anonuid=150,anongid=100)
> >> $ awk '{sub(/.*,anonuid=/,"");sub(/,.*$/,"")}1' file
> >> 150
>
> >> If you show a sample of where you want to match it against in /etc/passwd we can
> >> expand on that.
>
> >>         Ed.- Hide quoted text -
>
> >> - Show quoted text -
>
> > Ed. Thanks a lot for the quick reply.
>
> > I want to compare this uid, ie 150 (or more if there are any more in
> > the /etc/exports) to the 3rd field in /etc/passwd file. If there is NO
> > match with the entries in /etc/passwd file then this uid needs to be
> > flagged.
>
> Untested...
>
>   awk 'NR==FNR { sub(/.*,anonuid=/,""); sub(/,.*$/,""); a[$0]; next }
>        $3 in a { delete a[$3] }
>        END { for (id in a) print id }
>       ' /etc/exports FS=: /etc/passwd
>
> Janis
>
>
>
>
>
> > An example of /etc/passwd will be:
>
> > nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
> > mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
> > smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
> > pcap:x:77:77::/var/arpwatch:/sbin/nologin
> > xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
> > ntp:x:38:38::/etc/ntp:/sbin/nologin
> > gdm:x:42:42::/var/gdm:/sbin/nologin
>
> > Thanks,
>
> > Kush- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Thank you guys!!!! I just tried Ed's and it worked. I'm not sure about
what happens in the code but I will try and figure it out. Thanks
Janis too....

Kush

Kush
From: John W. Krahn on
Kush wrote:
> Hi folks.
>
> I need to get the value of just the 'uid' from a line in /etc/exports.
> For example, in the line below, I need to get the value '150', from
> the 'anonuid=150' value, and I need to verify that that is a valid uid
> by checking it against /etc/passwd:
>
> /home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
>
> I'm not very strong in sed/awk and all I can think of right now and I
> have tried is:
>
> cat /etc/exports | egrep /\.*/^/anonuid=
>
> but that is not even giving me the string I want.
>
> Any help will be greatly appreciated.

perl -lne'print /anonuid=(\d+)/ && getpwuid $1 ? "$1 exists" : "$1 not
there"' /etc/exports



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
From: John Kelly on
On Fri, 02 Jul 2010 11:33:15 -0700, "John W. Krahn"
<jwkrahn(a)example.com> wrote:

>> Any help will be greatly appreciated.

>perl -lne'print /anonuid=(\d+)/ && getpwuid $1 ? "$1 exists" : "$1 not
>there"' /etc/exports

After reading c.l.p.misc for a while, I have more appreciation for perl
one liners posted here. c.l.p.misc is a strange place.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php