I have the following script and when I run it, I don’t get the expected output to the local terminal.
I am assuming it must be the variables that I am assigning in the heredoc that is not getting printed as I expect.
#!/bin/bash
#
for host in `cat hosts.txt`
do
ssh $host << EOF
IP=`ip a |grep inet|grep ens192 | awk '{print $2}'`
CPU=`cat /proc/cpuinfo |grep "physical id" | wc -l`
MEM=`getconf -a | grep PAGESIZE | awk '{print $2}'`
DISK=`lsblk |grep disk | awk '{print $4}'`
EOF
done
printf "ip_address cpu memory diskn"
echo "---------- --- ------ ----"
printf "$IP $CPU $MEM $DISK"
I am not sure how to fix the issue. Also I hope that if hosts.txt contains 5 hosts, it would print 5 lines.
Thank you in advanced.