问题描述
我需要提取NFS使用安装
在Linux(RHEL 4/5)和Solaris(Solaris 10上)安装系统的信息。由于这是一个SSH命令的一部分,提取需要在一行中发生。不幸的是,Linux和Solaris在该行的不同部分显示挂载点:
Linux的:
10.0.0.1:/remote/export上/本地/挂载点otherstuff
Solaris上:
上10.0.0.1:/remote/export otherstuff /本地/挂载点
我想获得下列空格隔开输出
10.0.0.1 /远程/导出/本地/挂载点
我设法与 SED
单独做到这一点(的Solaris 10 SED
),但我需要一个命令returing的相同的输出为。
Linux的 SED
:
SED的/ \\([^:] * \\)\\([^] * \\)[^ \\ /] * \\([^] * \\)* / \\ 1 \\ 2 \\ 3 /'
的Solaris SED
:
SED的/ \\([^] * \\)*月* \\([^:] * \\)\\([^] * \\)* / \\ 2 \\ 3 \\ 1 /'
解决方案:
我适应了也与DNS名称并不仅仅是IP地址工作:
的awk -F'[:]''{如果(/ ^ \\ //)打印$ 3,$ 4,$ 1;否则打印$ 1,$ 2,$ 4}'
AWK可以帮助你:
的awk -F'[:]''{如果(/ ^ [0-9] /)打印$ 1,$ 2,$ 4;否则打印$ 3,$ 4,$ 1}
看到这样的测试:
肯特$猫˚F
10.0.0.1:/remote/export上/本地/挂载点otherstuff
在10.0.0.1:/remote/export otherstuff /本地/挂载点肯特$ awk的-F'[:]''{如果(/ ^ [0-9] /)打印$ 1,$ 2,$ 4;否则打印$ 3,$ 4,$ 1}'F
10.0.0.1 /远程/导出/本地/挂载点
10.0.0.1 /远程/导出/本地/挂载点
I need to extract NFS mount information using mount
on Linux (RHEL 4/5) and Solaris (Solaris 10) systems. As this is part of an SSH command, the extraction needs to happen in one line. Unfortunately, Linux and Solaris display the mountpoint at different parts of the line:
Linux:
10.0.0.1:/remote/export on /local/mountpoint otherstuff
Solaris:
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
I would like to get the following space separated output
10.0.0.1 /remote/export /local/mountpoint
I managed to do it separately with sed
(Solaris 10 sed
), but I need one command returing the same output for both.
Linux sed
:
sed 's/\([^:]*\):\([^ ]*\)[^\/]*\([^ ]*\) .*/\1 \2 \3/'
Solaris sed
:
sed 's/\([^ ]*\) *on *\([^:]*\):\([^ ]*\) .*/\2 \3 \1/'
Solution:
I adapted the accepted answer to also work with DNS names and not only IPs:
awk -F'[: ]' '{if(/^\//)print $3,$4,$1;else print $1,$2,$4}'
awk could help you:
awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}'
see this test:
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和Solaris的NFS信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!