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
OUTPUT IS:
/dev/vda3 27G 722M 26G 3% /export/brick
desired output = 27G
You need to escape the $2
to have it interpreted by awk
inside the ssh connection:
SCRIPT="df -h /dev/vda3 | grep '/export/brick' | awk '{print \$2}' ";
Also, note you can squeeze it a little bit, using the grep
condition inside the awk
:
SCRIPT="df -h /dev/vda3 | awk '/export\/brick/{print \$2}' ";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.