1

I am trying to fetch only column using awk in OS commands like uname -a , uptime, using pssh multiple commands, But it's not giving correct output. Using "uname -a" is just an example i have shown, I meant to say awk is not working even any of the command, I tried only particular field of uptime via awk but no luck. Please let me know, if there is any possibility..

My need is to place the commands in same line and Below is the command, I'm trying, which gives correct output. But Not with awk

pssh -h /tmp/hosts -i 'echo "$(echo -n);$(date);$(uname -a)"' 
[1] 13:41:35 [SUCCESS] server1 ;Sun Jan 27 12:41:35 UTC 2019;Linux server1 3.12.74-60.64.99-default #1 SMP Tue Aug 14 07:11:35 UTC 2018 (d28148a) x86_64 x86_64 x86_64 GNU/Linux 
[2] 13:41:35 [SUCCESS] server2 ;Sun Jan 27 12:41:35 UTC 2019;Linux server2 3.12.74-60.64.99-default #1 SMP Tue Aug 14 07:11:35 UTC 2018 (d28148a) x86_64 x86_64 x86_64 GNU/Linux

Below is the commands using with awk command is Not working

pssh -h /tmp/hosts -i 'echo "$(echo -n);$(date);$(uname -a|awk '{print \$3}')"'

[1] 13:54:54 [SUCCESS] server1 ;Sun Jan 27 12:54:54 UTC 2019; Stderr: awk: cmd. line:1: {print awk: cmd. line:1: ^ unexpected newline or end of string 
[2] 13:54:54 [SUCCESS] server2 ;Sun Jan 27 12:54:54 UTC 2019; Stderr: awk: cmd. line:1: {print awk: cmd. line:1: ^ unexpected newline or end of string

closed as unclear what you're asking by Jesse_b, RalfFriedl, mosvy, Mr Shunz, Archemar Jan 28 at 10:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Does pssh write its output to standard error maybe? I'm not familiar with the command... – Kusalananda Jan 26 at 19:31
  • I'm also not familiar with pssh (and not installed), but you want the hostname, right? pssh -h /tmp/cus2 -i hostname or pssh -h /tmp/cus2 -i sh -c "echo $(uname -a|awk '{print $2}')"? – Freddy Jan 26 at 20:29
  • what about: pssh -h /tmp/cus3 -i "uname -a|awk '{print \$3}'"? – Jesse_b Jan 26 at 21:36
  • I wonder why you're not using uname -n instead of uname -a | awk '{print $2}'. Anyways, in the 2nd example, the $3 will be expanded by the local shell (because it's in double quotes; probably to nothing), not by awk; to command thus run will be uname -a | awk '{print}'. I suspect that you were using double instead of single quotes when you have tested the 1st example, too. – mosvy Jan 27 at 3:29
  • 2
    In you new 2nd example the single quote just after awk will terminate the literal started by the quote just before echo. Try this instead: pssh -h /tmp/hosts -i 'echo "$(echo -n);$(date);$(uname -a|awk "{print \$2}")"'. It would help if you described what you're trying to achieve, instead of giving contrived examples that only demonstrate how nasty the shell quoting and escaping is. – mosvy Jan 27 at 15:24

Browse other questions tagged or ask your own question.