如何使用 bash 收集所有带有多个配置文件的 NFS 挂载点以检查每个挂载是否可写?

How can I use bash to gather all NFS mount points with multiple configuration files to check that each mount is writeable?

我正在尝试创建一个脚本,该脚本将动态查找所有 应该 可写的 NFS 挂载点,并检查它们是否仍然可写,但我似乎无法获取我的绕过将坐骑连接到它们的共享目录。

所以例如我有一个服务器的 /etc/auto.master 是这样的(我已经清理了一些数据):

/etc/auto.master
/nfs1        /etc/auto.nfs1 --ghost
/nfs2        /etc/auto.nfs2 --ghost

每个文件都有:

/etc/auto.nfs1
home   -rw,soft-intr -fstype=nfs server1:/shared/home
store  -rw,soft-intr -fstype=nfs server2:/shared/store

/etc/auto.nfs2
data   -rw,soft-intr -fstype=nfs oralceserver1:/shared/data
rman   -rw,soft-intr -fstype=nfs oracleserver1:/shared/rman

我想要摆脱的是

/nfs1/home
/nfs1/store

/nfs2/data
/nfs2/rman

没有在网上发现任何错误或评论的条目。

我的代码尝试是这样的:

#!/bin/bash

for automst in `grep '^/' /etc/auto.master|awk -F" " '{for(i=1;i<=NF;i++){if ($i ~ /etc/){print $i}}}'`;
do echo $automst > /tmp/auto.mst
done

AUTOMST=`cat /tmp/auto.mst`

for mastermount in `grep '^/' /etc/auto.master|awk -F" " '{for(i=1;i<=NF;i++){if ($i ~ /etc/){print $i}}}'`;
do grep . $mastermount|grep -v '#'|awk {'print '};
done > /tmp/nfsmounteddirs

for dir in `cat /tmp/nfsmounteddirs`;
do
if [ -w "$dir" ]; then echo "$dir is writeable"; else echo "$dir is not writeable!";fi
done

我有 600 台 Linux 服务器,许多服务器都有自己的 NFS 设置,我们没有可以检查的警报解决方案,虽然拥有所有这些单独的脚本将是“一个”解决方案, 这将是一场噩梦,需要大量的管理和工作,因此它的动态方面将非常有用。

awk '/^\// {  # Process where lines begin with a /
             fil=; # Track the file name
             nfs= # Track the nfs
             while (getline line < fil > 0) { # Read the fil specified by fil till the end of the file
                 split(line,map,","); # Split the lines in array map with , as the delimiter
                 split(map[1],map1,/[[:space:]]+/); # Further split map into map1 with spaces as the delimiter
                 if(map1[2]~/w/ && line !~ /^#/) { 
                   print nfs" "map1[1] # If w is in the permissions string and the line doesn't begin with a comment, print the nfs and share 
                 } 
             } 
             close(fil) # Close the file after we have finished reading
            }' /etc/auto.master

一个班轮:

awk '/^\// { fil=;nfs=;while (getline line < fil > 0) { split(line,map,",");split(map[1],map1,/[[:space:]]+/);if(map1[2]~/w/ && line !~ /^#/) { print nfs" "map1[1] } } close(fil) }' /etc/auto.master

输出:

/nfs1 home
/nfs1 store
/nfs2 data
/nfs2 rman