I am trying to make a bash script to get CPU and Memory information in different Unix servers and pipe them into a single text file in the local server.
The script returns something (result), but the result was not accurate when I check each of the servers CPU and Memory information manually. There might be some error in the scripts since the CPU and Memory commands are correct.
Here is the command to get CPU information in Unix (HPUX) :
machinfo | grep CPUs | awk '{print $5}'
And the result will be :
4
And here is the command to get Memory information in Unix (HPUX) :
machinfo | grep Memory | awk '{print $3}'
And the result will be :
4090
It shows that the commands are correct. Let's go into the full scripts.
#!/bin/ksh
SERVERS='
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx'
cpu=$(machinfo | grep CPUs | awk '{print $5}')
mem=$(machinfo | grep Memory | awk '{print $3}')
print "SERVER" "CPU" "RAM (MB)";
for i in $SERVERS
do
ssh -n $i 2>&1 '$cpu | $mem'
print $cpu $mem
done
When the full scripts run, the result will be:
SERVER CPU RAM (MB)
s24bf011 2 4090
s24bf012 2 4090
s24bf013 2 4090
s24bf014 2 4090
s24bf016 2 4090
S24BF104 2 4090
S24BF105 2 4090
10.14.24.158 2 4090
S29BF200 2 4090
S02BF131 2 4090
S02BF104 2 4090
S24BF071 2 4090
S24BF165 2 4090
10.14.24.17 2 4090
Every server has a different CPU and RAM. How come they were all the same? Error in SSHing?