Article 5N5MC [SOLVED] Another "syntax error" while using awk when accessing remote servers

[SOLVED] Another "syntax error" while using awk when accessing remote servers

by
brh1
from LinuxQuestions.org on (#5N5MC)
Good day.

This command works nicely on a local server to display the CPU usage:

Code:-bash-4.2$ grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'
26.5474%
-bash-4.2$However, when I try to query the CPU usage on remote servers I get a 'syntax error':

Code:-bash-4.2$ for h in {12..17} ; do echo;ssh -q -o "StrictHostKeyChecking no" 192.168.210.$h "uname -n;grep 'cpu ' /proc/stat | awk '{cpu_usage=(\$2+\$4)*100/(\$2+\$4+\$5)} END {print cpu_usage "%"}'";done
remote-vm101sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error

remote-vm102sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error

remote-vm103sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error

remote-vm104sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error

remote-vm105sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error

remote-vm106sip001
awk: cmd. line:1: {cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage %}
awk: cmd. line:1: ^ syntax error
-bash-4.2$I've tried backslashes, ^, quotes, to no avail. It also works without the '"%"' but I thought it would look better with the percentage sign.

Please advise.

Bjoernlatest?d=yIl2AUoC8zA latest?i=d3wG4iIr67o:z-lIWCrFKaU:F7zBnMy latest?i=d3wG4iIr67o:z-lIWCrFKaU:V_sGLiP latest?d=qj6IDK7rITs latest?i=d3wG4iIr67o:z-lIWCrFKaU:gIN9vFwd3wG4iIr67o
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments