In some places awk doesn't work in pssh command
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
bash awk
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
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
bash awk
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
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
bash awk
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
bash awk
bash awk
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
steeldriver
67.2k11108180
67.2k11108180
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Sin15Sin15
11
11
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sin15 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can see what's going wrong if you turn on bash shell debugging
$ set -x
$ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk '{print $3}')"'
+ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk {print' '})"'
So the invoking shell is splitting the command into two arguments:
echo "$(uname -a | awk {print
and
$3})"
(with $3 being expanded to an empty value). This is one of the (rare) cases where the usual "if in doubt, add quotes" doesn't help you - the double quotes around the command substitution in the echo aren't really necessary, and if you remove them you can get rid of one level of quote nesting. Then you can just do
$ parallel-ssh -h hostsfile -i 'echo $(date) $(uname -a|awk "{print $3}")'
[1] 09:13:36 [SUCCESS] vm
Sun Jan 27 09:13:36 EST 2019 4.4.0-141-generic
[2] 09:13:37 [SUCCESS] localhost
Sun Jan 27 09:13:37 EST 2019 4.15.0-43-generic
where
single quotes around the whole
psshargument prevent the invoking shell from expanding and running the command substitutions locallydouble quotes around the
awkexpression DON'T prevent$3frombeing expanded by the remote shell, so backslash escape it
Alternatively, you can add literal single quotes around the awk expression by opening and closing the single quotes:
'echo $(date) $(uname -a|awk '''{print $3}''')'
Thank you @steeldriver
– Sin15
2 days ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sin15 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1113260%2fin-some-places-awk-doesnt-work-in-pssh-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can see what's going wrong if you turn on bash shell debugging
$ set -x
$ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk '{print $3}')"'
+ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk {print' '})"'
So the invoking shell is splitting the command into two arguments:
echo "$(uname -a | awk {print
and
$3})"
(with $3 being expanded to an empty value). This is one of the (rare) cases where the usual "if in doubt, add quotes" doesn't help you - the double quotes around the command substitution in the echo aren't really necessary, and if you remove them you can get rid of one level of quote nesting. Then you can just do
$ parallel-ssh -h hostsfile -i 'echo $(date) $(uname -a|awk "{print $3}")'
[1] 09:13:36 [SUCCESS] vm
Sun Jan 27 09:13:36 EST 2019 4.4.0-141-generic
[2] 09:13:37 [SUCCESS] localhost
Sun Jan 27 09:13:37 EST 2019 4.15.0-43-generic
where
single quotes around the whole
psshargument prevent the invoking shell from expanding and running the command substitutions locallydouble quotes around the
awkexpression DON'T prevent$3frombeing expanded by the remote shell, so backslash escape it
Alternatively, you can add literal single quotes around the awk expression by opening and closing the single quotes:
'echo $(date) $(uname -a|awk '''{print $3}''')'
Thank you @steeldriver
– Sin15
2 days ago
add a comment |
You can see what's going wrong if you turn on bash shell debugging
$ set -x
$ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk '{print $3}')"'
+ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk {print' '})"'
So the invoking shell is splitting the command into two arguments:
echo "$(uname -a | awk {print
and
$3})"
(with $3 being expanded to an empty value). This is one of the (rare) cases where the usual "if in doubt, add quotes" doesn't help you - the double quotes around the command substitution in the echo aren't really necessary, and if you remove them you can get rid of one level of quote nesting. Then you can just do
$ parallel-ssh -h hostsfile -i 'echo $(date) $(uname -a|awk "{print $3}")'
[1] 09:13:36 [SUCCESS] vm
Sun Jan 27 09:13:36 EST 2019 4.4.0-141-generic
[2] 09:13:37 [SUCCESS] localhost
Sun Jan 27 09:13:37 EST 2019 4.15.0-43-generic
where
single quotes around the whole
psshargument prevent the invoking shell from expanding and running the command substitutions locallydouble quotes around the
awkexpression DON'T prevent$3frombeing expanded by the remote shell, so backslash escape it
Alternatively, you can add literal single quotes around the awk expression by opening and closing the single quotes:
'echo $(date) $(uname -a|awk '''{print $3}''')'
Thank you @steeldriver
– Sin15
2 days ago
add a comment |
You can see what's going wrong if you turn on bash shell debugging
$ set -x
$ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk '{print $3}')"'
+ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk {print' '})"'
So the invoking shell is splitting the command into two arguments:
echo "$(uname -a | awk {print
and
$3})"
(with $3 being expanded to an empty value). This is one of the (rare) cases where the usual "if in doubt, add quotes" doesn't help you - the double quotes around the command substitution in the echo aren't really necessary, and if you remove them you can get rid of one level of quote nesting. Then you can just do
$ parallel-ssh -h hostsfile -i 'echo $(date) $(uname -a|awk "{print $3}")'
[1] 09:13:36 [SUCCESS] vm
Sun Jan 27 09:13:36 EST 2019 4.4.0-141-generic
[2] 09:13:37 [SUCCESS] localhost
Sun Jan 27 09:13:37 EST 2019 4.15.0-43-generic
where
single quotes around the whole
psshargument prevent the invoking shell from expanding and running the command substitutions locallydouble quotes around the
awkexpression DON'T prevent$3frombeing expanded by the remote shell, so backslash escape it
Alternatively, you can add literal single quotes around the awk expression by opening and closing the single quotes:
'echo $(date) $(uname -a|awk '''{print $3}''')'
You can see what's going wrong if you turn on bash shell debugging
$ set -x
$ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk '{print $3}')"'
+ parallel-ssh -h hostsfile -i 'echo "$(uname -a | awk {print' '})"'
So the invoking shell is splitting the command into two arguments:
echo "$(uname -a | awk {print
and
$3})"
(with $3 being expanded to an empty value). This is one of the (rare) cases where the usual "if in doubt, add quotes" doesn't help you - the double quotes around the command substitution in the echo aren't really necessary, and if you remove them you can get rid of one level of quote nesting. Then you can just do
$ parallel-ssh -h hostsfile -i 'echo $(date) $(uname -a|awk "{print $3}")'
[1] 09:13:36 [SUCCESS] vm
Sun Jan 27 09:13:36 EST 2019 4.4.0-141-generic
[2] 09:13:37 [SUCCESS] localhost
Sun Jan 27 09:13:37 EST 2019 4.15.0-43-generic
where
single quotes around the whole
psshargument prevent the invoking shell from expanding and running the command substitutions locallydouble quotes around the
awkexpression DON'T prevent$3frombeing expanded by the remote shell, so backslash escape it
Alternatively, you can add literal single quotes around the awk expression by opening and closing the single quotes:
'echo $(date) $(uname -a|awk '''{print $3}''')'
answered 2 days ago
steeldriversteeldriver
67.2k11108180
67.2k11108180
Thank you @steeldriver
– Sin15
2 days ago
add a comment |
Thank you @steeldriver
– Sin15
2 days ago
Thank you @steeldriver
– Sin15
2 days ago
Thank you @steeldriver
– Sin15
2 days ago
add a comment |
Sin15 is a new contributor. Be nice, and check out our Code of Conduct.
Sin15 is a new contributor. Be nice, and check out our Code of Conduct.
Sin15 is a new contributor. Be nice, and check out our Code of Conduct.
Sin15 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1113260%2fin-some-places-awk-doesnt-work-in-pssh-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown