Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script that runs the command mount -v 2>/some/file, which I then parse with another script using the following regex:

^.*[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*

The problem I am having is this: there are a few NFS mounts that have waivers excluding them from being mounted with nosuid (they're Solaris 11 IPS repositories). Now I need to modify my regex to exclude a known mount...

To provide a point of reference, here's some sample output from mount -v:

$ mount -v
/dev/dsk/c1t0d0s0                 on  /                  type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840000  on  Fri  Sep  6   12:10:35  2013
/devices                          on  /devices           type  devfs    read/write/setuid/devices/rstchown/dev=4c00000                                             on  Fri  Sep  6   12:10:25  2013
ctfs                              on  /system/contract   type  ctfs     read/write/setuid/devices/rstchown/dev=4c80001                                             on  Fri  Sep  6   12:10:25  2013
proc                              on  /proc              type  proc     read/write/setuid/devices/rstchown/dev=4c40000                                             on  Fri  Sep  6   12:10:25  2013
mnttab                            on  /etc/mnttab        type  mntfs    read/write/setuid/devices/rstchown/dev=4cc0001                                             on  Fri  Sep  6   12:10:25  2013
swap                              on  /etc/svc/volatile  type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00001                                       on  Fri  Sep  6   12:10:25  2013
objfs                             on  /system/object     type  objfs    read/write/setuid/devices/rstchown/dev=4d40001                                             on  Fri  Sep  6   12:10:25  2013
sharefs                           on  /etc/dfs/sharetab  type  sharefs  read/write/setuid/devices/rstchown/dev=4d80001                                             on  Fri  Sep  6   12:10:25  2013
/usr/lib/libc/libc_hwcap1.so.1    on  /lib/libc.so.1     type  lofs     read/write/setuid/devices/rstchown/dev=840000                                              on  Fri  Sep  6   12:10:31  2013
fd                                on  /dev/fd            type  fd       read/write/setuid/devices/rstchown/dev=4f00001                                             on  Fri  Sep  6   12:10:35  2013
swap                              on  /tmp               type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00002                                       on  Fri  Sep  6   12:10:38  2013
swap                              on  /var/run           type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00003                                       on  Fri  Sep  6   12:10:38  2013
/dev/dsk/c1t0d0s7                 on  /export/home       type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840007  on  Fri  Sep  6   12:10:44  2013
sample-ips:/ips/blargSolaris11.1  on  /blargSolaris11.1  type  nfs      remote/read/write/setuid/devices/rstchown/soft/xattr/dev=8c00001                           on  Tue  Sep  10  12:07:46  2013

I had tried modifying the regex to exclude the IP's mount based on matching the mount at the beginning of the line like this:

^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*

But it's not working...

share|improve this question
    
I don't know about Solaris mount, but Linux one can take the -t parameter, with which you can restrict the output to file systems of certain type. That could cut your regex down. –  peterph Sep 25 '13 at 21:05
add comment

1 Answer

Not sure what you're doing with that regular expression but it seems fine to me. It appears to be Perl, so using the GNU version of grep's -P switch I used your regex like so:

$ column -t mount.txt | \
     grep -vP '^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*'

Example

$ column -t mount.txt | \
     grep -vP '^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*'
/dev/dsk/c1t0d0s0                 on  /                  type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840000  on  Fri  Sep  6   12:10:35  2013
/devices                          on  /devices           type  devfs    read/write/setuid/devices/rstchown/dev=4c00000                                             on  Fri  Sep  6   12:10:25  2013
ctfs                              on  /system/contract   type  ctfs     read/write/setuid/devices/rstchown/dev=4c80001                                             on  Fri  Sep  6   12:10:25  2013
proc                              on  /proc              type  proc     read/write/setuid/devices/rstchown/dev=4c40000                                             on  Fri  Sep  6   12:10:25  2013
mnttab                            on  /etc/mnttab        type  mntfs    read/write/setuid/devices/rstchown/dev=4cc0001                                             on  Fri  Sep  6   12:10:25  2013
swap                              on  /etc/svc/volatile  type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00001                                       on  Fri  Sep  6   12:10:25  2013
objfs                             on  /system/object     type  objfs    read/write/setuid/devices/rstchown/dev=4d40001                                             on  Fri  Sep  6   12:10:25  2013
sharefs                           on  /etc/dfs/sharetab  type  sharefs  read/write/setuid/devices/rstchown/dev=4d80001                                             on  Fri  Sep  6   12:10:25  2013
/usr/lib/libc/libc_hwcap1.so.1    on  /lib/libc.so.1     type  lofs     read/write/setuid/devices/rstchown/dev=840000                                              on  Fri  Sep  6   12:10:31  2013
fd                                on  /dev/fd            type  fd       read/write/setuid/devices/rstchown/dev=4f00001                                             on  Fri  Sep  6   12:10:35  2013
swap                              on  /tmp               type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00002                                       on  Fri  Sep  6   12:10:38  2013
swap                              on  /var/run           type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00003                                       on  Fri  Sep  6   12:10:38  2013
/dev/dsk/c1t0d0s7                 on  /export/home       type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840007  on  Fri  Sep  6   12:10:44  2013

You'll notice the line starting with the sample-ips:/ips/blargSolaris11.1 is being filtered out as you're intending.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.