Beware of those curly quotes (“
and ”
) some Windows text editors will use, use straight quotes instead ('
or "
). You should also be using '
s, unless you have some reason to use "
s, e.g. to let a variable expand, see https://mywiki.wooledge.org/Quotes.
You should be doing this if you want a single pipe to awk:
{ ssh username@host1 'cat /tmp/test/*'; ssh username@host2 'cat /tmp/test/*'; } | awk ' command '
but consider doing this instead so awk can distinguish which command the input came from in case you need that distinction in future:
awk ' command ' <(ssh username@host1 'cat /tmp/test/*') <(ssh username@host2 'cat /tmp/test/*')
Here's the difference:
$ seq 3 > file1
$ seq 2 > file2
Wrong output (because FILENAME
always contains -
and ARGV[1..2]
are empty):
$ { cat file1; cat file2; } | awk '
FILENAME == ARGV[1] { host="host1" }
FILENAME == ARGV[2] { host="host2" }
{ print host, $0 }
'
1
2
3
1
2
Wrong output (because FILENAME
and ARGV[1]
contain the same temp file descriptor but ARGV[2]
is empty):
$ awk '
FILENAME == ARGV[1] { host="host1" }
FILENAME == ARGV[2] { host="host2" }
{ print host, $0 }
' <(cat file1; cat file2)
host1 1
host1 2
host1 3
host1 1
host1 2
Correct output:
$ awk '
FILENAME == ARGV[1] { host="host1" }
FILENAME == ARGV[2] { host="host2" }
{ print host, $0 }
' <(cat file1) <(cat file2)
host1 1
host1 2
host1 3
host2 1
host2 2
Other possible way to get the correct output with this approach of providing the input:
$ awk '{print host, $0}' host='host1' <(cat file1) host='host2' <(cat file2)
host1 1
host1 2
host1 3
host2 1
host2 2
ssh host1 command shh host2 command
which is interpreted asssh host1 "command ssh host2 command"
, so the command run on the first host iscat /tmp/test/* ssh host2 cat /tmp/test/*
socat
is given everything else as an argument. See my updated answer.cat: ssh: No such file or directory
or similar that they decided not to tell us about which is.... disappointing. It also once again makes me think the code in the question isn't the actual code the OP is running.bash: line 1: $'\342\200\234cat': command not found
because of the fancy quotes, but if normal quotes are used, they will be as you said and I show in my answer. @NecroCoder for next time, please make sure to check the errors and include them in any future questions.