From: Kush on
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
From: Ed Morton on
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.
From: Kush on
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.

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
From: Ed Morton on
On 7/2/2010 12:00 PM, 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.
>
> 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

Try this:

awk -F: '
NR==FNR { if (sub(/.*,anonuid=/,"")) { sub(/,.*$/,""); uids[$0] } next }
{ delete uids[$3] }
END { for (uid in uids) print uid " not found"}
' /etc/exports /etc/passwd

Ed.
From: Janis Papanagnou on
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