[CentOS] ssh remote execute awk problem

Thu Mar 17 10:45:08 UTC 2011
sync <jiannma at gmail.com>

Hi , all :


There is a problem on executing awk command to remote servers;

The shell test script is like this :



   1. #!/bin/sh
   2.
   3. _CMD="ssh root at localhost"
   4.
   5. cpu_num="$($_CMD awk '/processor/{count["proc"]++}; END{print
   count["proc"]}' /proc/cpuinfo)“
   6.
   7. echo $cpu_num


My root account can entry the server without the passwd.

But  I found no result on the screen .

Is there some error on that script ? By the way , I googled and found use
the following method can run the right result .


   1. #!/bin/sh
   2.
   3. _CMD="ssh root at localhost"
   4.
   5. cpu_num="$($_CMD  << 'HERE'
   6. awk '/processor/{count["proc"]++}; END{print count["proc"]}'
   /proc/cpuinfo
   7. HERE
   8.
   9. )“
   10.
   11. echo $cpu_num
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos/attachments/20110317/bedac8bf/attachment-0004.html>