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@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@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
From: sync jiannma@gmail.com
There is a problem on executing awk command to remote servers;
- #!/bin/sh
- _CMD="ssh root@localhost"
- cpu_num="$($_CMD awk '/processor/{count["proc"]++}; END{print
count["proc"]}' /proc/cpuinfo)“ 6. 7. echo $cpu_num
Quote the whole command and backslash the command quotes... ssh root@localhost "awk '/processor/{count["proc"]++}; END{print count["proc"] } ' /proc/cpuinfo"
JD
On Thu, Mar 17, 2011 at 6:58 AM, John Doe jdmls@yahoo.com wrote:
From: sync jiannma@gmail.com
There is a problem on executing awk command to remote servers; 1. #!/bin/sh 2. 3. _CMD="ssh root@localhost" 4. 5. cpu_num="$($_CMD awk '/processor/{count["proc"]++}; END{print count["proc"]}' /proc/cpuinfo)“ 6. 7. echo $cpu_num
Quote the whole command and backslash the command quotes... ssh root@localhost "awk '/processor/{count["proc"]++}; END{print count["proc"] } ' /proc/cpuinfo"
JD
Or do the processing locally and stay away from proc nuttiness, without mucking with ssh and awk.
grep ^processor /proc/cpuinfo | wc -l
Or:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep ^processor | wc -l"
On Thu, Mar 17, 2011 at 9:31 AM, Nico Kadel-Garcia nkadel@gmail.com wrote:
On Thu, Mar 17, 2011 at 6:58 AM, John Doe jdmls@yahoo.com wrote:
From: sync jiannma@gmail.com
There is a problem on executing awk command to remote servers; 1. #!/bin/sh 2. 3. _CMD="ssh root@localhost" 4. 5. cpu_num="$($_CMD awk '/processor/{count["proc"]++}; END{print count["proc"]}' /proc/cpuinfo)“ 6. 7. echo $cpu_num
Quote the whole command and backslash the command quotes... ssh root@localhost "awk '/processor/{count["proc"]++}; END{print count["proc"] } ' /proc/cpuinfo"
JD
Or do the processing locally and stay away from proc nuttiness, without mucking with ssh and awk.
grep ^processor /proc/cpuinfo | wc -l
Or:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep ^processor | wc -l"
Ooops! I meant
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep ^processor /proc/cpuinfo | wc -l"
The check fo rprocinfo is in case /proc isn't mounted.
On 3/17/2011 8:31 AM, Nico Kadel-Garcia wrote:
Quote the whole command and backslash the command quotes... ssh root@localhost "awk '/processor/{count["proc"]++}; END{print count["proc"] } ' /proc/cpuinfo"
JD
Or do the processing locally and stay away from proc nuttiness, without mucking with ssh and awk.
grep ^processor /proc/cpuinfo | wc -l
Or:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep
^processor | wc -l"
Or, more extremely - if you are doing much of this kind of remote inventory checking, you might consider running ocsinventory-ng with agents on the nodes.
Les Mikesell wrote:
On 3/17/2011 8:31 AM, Nico Kadel-Garcia wrote:
Quote the whole command and backslash the command quotes... ssh root@localhost "awk '/processor/{count["proc"]++}; END{print count["proc"] } ' /proc/cpuinfo"
Or do the processing locally and stay away from proc nuttiness, without mucking with ssh and awk.
grep ^processor /proc/cpuinfo | wc -l
Or:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep
^processor | wc -l"
Or, more extremely - if you are doing much of this kind of remote inventory checking, you might consider running ocsinventory-ng with agents on the nodes.
Yes. We use ocsinventory here. Warning: there are a few systems that ocsinventory, or at least the version we put on last year, would literally crash or hang the system.
mark
On 3/17/2011 9:43 AM, m.roth@5-cent.us wrote:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep
^processor | wc -l"
Or, more extremely - if you are doing much of this kind of remote inventory checking, you might consider running ocsinventory-ng with agents on the nodes.
Yes. We use ocsinventory here. Warning: there are a few systems that ocsinventory, or at least the version we put on last year, would literally crash or hang the system.
They seem to be nearing a 2.x release where the new server will talk to the old clients but not the other way around (due to the db utf8 settings). But I haven't seen any serious problems with the old agent except that on windows the service sometimes stops running, and it doesn't see the 64-bit registry.
________________________________ From: Nico Kadel-Garcia nkadel@gmail.com To: CentOS mailing list centos@centos.org Sent: Thu, March 17, 2011 6:31:15 AM Subject: Re: [CentOS] ssh remote execute awk problem
grep ^processor /proc/cpuinfo | wc -l
Or:
ssh -l $TARGETUSER $TARGETHOST "[ -e /proc/cpuinfo ] -a grep
^processor | wc -l"
No need to use "wc -l" when grep is enough. E.g
ssh root@server "grep -c ^processor /proc/cpuinfo" 4
Thanks Sheraz