0

I can't seem to get this script to work. I am trying to query the amount of cpu's on a list of nodes in a file.

readarray fnames < nodes.txt

for fn in "${fnames[@]}"
do
  com="ssh $fn `cat /proc/cpuinfo | grep processor | wc -l`"
  com=${com: -2}
  echo $fn                        $com
done

It should print the hostname than number of cpu's. Instead it prints the hostname and 8 every time. I suspect the 8 is because of

bash: 8: command not found

being displayed.

1
  • I noticed it seems to always run the cat /proc/cpuinfo | grep processor | wc -l for the current hostname, which why it always returns 8. Commented Jan 29, 2015 at 17:31

1 Answer 1

1

Change it to this :

readarray fnames < nodes.txt

for fn in "${fnames[@]}"
do
  echo "getinfo:$fn"
  com="ssh $fn cat /proc/cpuinfo | grep processor | wc -l"
  com1=$($com) # or com1=`$com`
  echo "$fn                        $com1"
done
Sign up to request clarification or add additional context in comments.

4 Comments

It comes up with ./cpus.sh: line 14: com: command not found error.
@JacquesMALAPRADE , is this linux ? what version ? show listing
@JacquesMALAPRADE , made change : com1=$($com)
I am running Ubuntu 14.04. I managed to get it to work. I will edit it above. Needs to be com1=backquote$com backquote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.