title: Get CPU and Memory Info In Different HPUX unix Servers
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Here is the command to get CPU information in Unix (HPUX) :</p>
  
  <pre><code>machinfo | grep CPUs | awk '{print $5}'
  </code></pre>
  
  <p>And the result will be :</p>
  
  <pre><code>4
  </code></pre>
  
  <p>And here is the command to get Memory information in Unix (HPUX) :</p>
  
  <pre><code>machinfo | grep Memory | awk '{print $3}'
  </code></pre>
  
  <p>And the result will be :</p>
  
  <pre><code>4090
  </code></pre>
  
  <p>It shows that the commands are correct. Let's go into the full scripts.</p>
  
  <pre><code>#!/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&gt;&amp;1 '$cpu | $mem'
    print $cpu $mem
  done
  </code></pre>
  
  <p>When the full scripts run, the result will be:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Every server has a different CPU and RAM. How come they were all the same?
  Error in SSHing?</p>