-1

I am trying to get the OS command from user input and export and use in function, like below

export command5=date
export command4=uname

Its working in below command

pssh -h /tmp/cus6 -i "$command5;$command4"
[1] 04:17:06 [SUCCESS] Server1
Mon Jan 28 03:17:06 UTC 2019
Linux
[2] 04:17:06 [SUCCESS] Server2
Mon Jan 28 03:17:06 UTC 2019
Linux

But didn't work when trying to keep commands in one line

pssh -h /tmp/cus6 -i 'echo $(echo ), $(command5), $(command4)'
[1] 04:26:45 [SUCCESS] Server1
, ,
Stderr: bash: command5: command not found
bash: command4: command not found
[2] 04:26:45 [SUCCESS] Server2
, ,
Stderr: bash: command5: command not found
bash: command4: command not found

But same is working in keeping commands instead of command5 & command4

pssh -h /tmp/cus6 -i 'echo $(echo ), $(date), $(uname)'
[1] 04:30:01 [SUCCESS] Server1
, Mon Jan 28 03:30:01 UTC 2019, Linux
[2] 04:30:01 [SUCCESS] Server2
, Mon Jan 28 03:30:01 UTC 2019, Linux
1

In order for the local variable to be expanded, you will need to replace the outer single quotes with double quotes.

Then, in order to pass the command substitution to the remote shell, you will need to quote (or escape) that.

Ex.

$ cmd='uname -r'

$ parallel-ssh -h hostsfile -i "echo \$($cmd)"
[1] 22:38:52 [SUCCESS] vm
4.4.0-141-generic
[2] 22:38:52 [SUCCESS] localhost
4.15.0-43-generic

Related: In some places awk doesn't work in pssh command

1
  • awk again having an issue, when user inputs any command with awk - uname -a|awk "{print \$3}" is not taking . command1:, command, not found – Sin15 Jan 28 '19 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.