I have a script to get server health from multiple servers like this:
#!/bin/bash
for ip
do
ssh 192.168.1.209 ssh root@$ip cat /proc/loadavg | awk '{print $1}' #CPU Usage
free | grep Mem | awk '{print $3/$2 * 100.0}' #Memory Usage
df -khP | awk '{print $3 "/" $2}' | awk 'FNR == 2' #Disk Space
df -kihP | awk '{print $3 "/" $2}' | awk 'FNR == 2' #Inode Space
date +'%d %b %Y %r %Z' #Datetime
ps -eo user,pid,pcpu,pmem,args|sort -nr -k3|head -5 #Process
done
The 209 is acting like a portal on my network so I have to ssh to it 1st in order to access other servers. By typing this command on terminal:
./my_script.sh 192.168.1.210 192.168.1.211 192.168.1.212
I would like to get each of the command output (ps,date etc) from each server. Expected output for 2 servers should be like:
0.11 #health from server 1
4.82577
1.7G/49G
46K/49M
27 Dec 2016 05:34:57 PM HKT
root 93 0.0 0.0 [kauditd]
root 9 0.0 0.0 [rcuob/0]
root 8740 0.0 0.0 ifstat --scan=100
root 829 0.0 0.0 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid
0.00 #health from server 2
4.82422
1.7G/49G
46K/49M
27 Dec 2016 05:34:57 PM HKT
root 93 0.0 0.0 [kauditd]
root 9 0.0 0.0 [rcuob/0]
root 8740 0.0 0.0 ifstat --scan=100
root 829 0.0 0.0 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid
The problem that I'm facing is that It seems like it's only getting the health info from one server only. Why is that? Is it because I cannot do SSH like this? I'm using PHP exec() function to execute the script btw, to further format and display it on my local page.