0

im using this script

[test@sys-master ~]$ parallel -k -j 100 sshpass -p test1213'!' ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -q [email protected].{} "cat /proc/loadavg | awk -F \" \" '{ print a,\$1,b }' a="'"$(hostname)"'" b=\$(nproc)" ::: {41..46}.{1..100} 

why return back local value? i need remote(node) values

 sys-master 9.87 24 sys-master 9.99 24 sys-master 11.85 24 sys-master 11.67 24 sys-master 10.75 24 sys-master 8.00 24 sys-master 10.27 24 sys-master 11.94 24 sys-master 10.28 24 sys-master 10.94 24 sys-master 12.02 24 sys-master 9.55 24 sys-master 11.43 2 
3
  • You only need the cat on the remote server, the rest can be done locally. Things like this are also easily done using Ansible. Also, you have a typo (a missing backslash in front of $(hostname)).
    – Kusalananda
    CommentedJan 21, 2022 at 9:33
  • parallel -k -j 100 sshpass -p test1213\! ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -q [email protected].{} "</proc/loadavg awk -v hostName='$(hostname)' -v nProc='$(nproc)' '{ print hostName, \$1, nProc }'" ::: {41..46}.{1..100}, I'm not posting this as an answer since I'm not sure it there is any other issues with parallel commnad syntax (because I never used it).CommentedJan 21, 2022 at 11:25
  • cat /proc/loadavg | awk 'foo' = awk 'foo' /proc/loadavg. See porkmail.org/era/unix/award.html#cat.
    – Ed Morton
    CommentedJan 21, 2022 at 14:06

1 Answer 1

0

It is due to quoting.

GNU Parallel is not part of the shell so every input has to be quoted if it would be interpreted by the shell. And since you call GNU Parallel from a shell (which will interpret input) and GNU Parallel starts a shell (that interprets the input) it has to be quoted twice, unless you use -q, which you can only use if you need the full line to be quoted (i.e. no composed command).

As you can tell it very quickly get confusing. :)

So the general recommendation is to define a bash function and call that.

myloadavg() { sshpass -p test1213'!' ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -q [email protected].$1 "cat /proc/loadavg | awk -F \" \" '{ print a,\$1,b }' a="'"\$(hostname)"'" b=\$(nproc)" } export -f myloadavg parallel myloadavg ::: {41..46}.{1..100} 
1
  • You also evaluate $(hostname) locally, which was what the actual question was about.
    – Kusalananda
    CommentedJan 21, 2022 at 9:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.