2014-02-05 62 views
0
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 

輸出是:選擇文本使用awk命令

/dev/vda3    27G 722M 26G 3% /export/brick 

期望的輸出= 27G

回答

2

您需要躲避$2把它解釋由awk ssh連接內:

SCRIPT="df -h /dev/vda3 | grep '/export/brick' | awk '{print \$2}' "; 

另外,請注意你可以擠它一個ttle位,使用內的grep條件:

SCRIPT="df -h /dev/vda3 | awk '/export\/brick/{print \$2}' ";