我需要在 Linux (RHEL 4/5) 和 Solaris (Solaris 10) 系统上使用 mount
提取 NFS 挂载信息。由于这是 SSH 命令的一部分,因此提取需要在一行中进行。不幸的是,Linux 和 Solaris 在该行的不同部分显示挂载点:
Linux:
10.0.0.1:/remote/export on /local/mountpoint otherstuff
索拉里:
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
我想得到以下空格分隔的输出
10.0.0.1 /remote/export /local/mountpoint
我设法用 sed
(Solaris 10 sed
) 单独完成它,但我需要一个命令为两者返回相同的输出。
Linux sed
:
sed 's/\([^:]*\):\([^ ]*\)[^\/]*\([^ ]*\) .*/\1 \2 \3/'
Solaris sed
:
sed 's/\([^ ]*\) *on *\([^:]*\):\([^ ]*\) .*/\2 \3 \1/'
解决方案:
我改编了accepted answer还可以使用 DNS 名称而不仅仅是 IP:
awk -F'[: ]' '{if(/^\//)print $3,$4,$1;else print $1,$2,$4}'
最佳答案
awk 可以帮助您:
awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}'
查看此测试:
kent$ cat f
10.0.0.1:/remote/export on /local/mountpoint otherstuff
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
kent$ awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}' f
10.0.0.1 /remote/export /local/mountpoint
10.0.0.1 /remote/export /local/mountpoint
关于linux - 如何从 Linux 和 Solaris 上的挂载中提取 NFS 信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20974140/