用于查找未使用 nosuid 挂载的 NFS 文件系统的正则表达式(有特殊需要的除外)

用于查找未使用 nosuid 挂载的 NFS 文件系统的正则表达式(有特殊需要的除外)

我有一个运行 command 的脚本mount -v 2>/some/file,然后使用以下正则表达式使用另一个脚本对其进行解析:

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

我遇到的问题是:有一些 NFS 挂载具有豁免,禁止它们挂载nosuid(它们是 Solaris 11 IPS 存储库)。现在我需要修改我的正则表达式以排除已知的安装...

为了提供参考,这里有一些示例输出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

我尝试修改正则表达式以根据匹配行开头的安装排除 IP 的安装,如下所示:

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

但这不起作用...

答案1

不确定你用这个正则表达式做什么,但对我来说似乎很好。它似乎是 Perl,所以使用 GNU 版本的 grep-P开关,我使用了你的正则表达式,如下所示:

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

例子

$ 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

您会注意到以 开头的行已sample-ips:/ips/blargSolaris11.1按照您的预期被过滤掉。

相关内容