USERNAME=root
HOSTS="192.168.122.91 192.168.122.102 192.168.122.180"
SCRIPT="df -h /dev/vda3 | grep '/export/brick' | awk '{print $2}' ";
for HOSTNAME in ${HOSTS} ; do
(ssh -l ${USERNAME} ${HOSTNAME} "${SCRIPT}")
done
输出是:
/dev/vda3 27G 722M 26G 3% /export/brick
所需输出= 27G
答案 0 :(得分:2)
你需要转义$2
以便在ssh连接中由awk
解释它:
SCRIPT="df -h /dev/vda3 | grep '/export/brick' | awk '{print \$2}' ";
另外,请注意,您可以使用grep
内的awk
条件轻轻挤压它:
SCRIPT="df -h /dev/vda3 | awk '/export\/brick/{print \$2}' ";