Re: Executing awk in a remote solaris server using ssh



Karthik <v.karthick@xxxxxxxxx> wrote:
On Oct 24, 11:45 pm, and...@xxxxxxxxxxxxxxxxxxxx (Andrew Gabriel)
wrote:
In article <1193264211.792216.153...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Karthik <v.karth...@xxxxxxxxx> writes:



Hello Everybody,

I'm facing a weird problem with the awk command.

I'm trying to execute a simple awk command as follows,

echo 1 2 | awk '{print $2}'

This command prints the output 2.

When i try to execute the same command in a remote server using ssh as
follows,

ssh user@host <<HERE
echo 1 2 | awk '{print $2}'
HERE

The output i get is '1 2' instead of just 2.

Try:

cat <<HERE
echo 1 2 | awk '{print $2}'
HERE

and you'll see why.

However, you are not really using ssh correctly here.
You probably want something more like:

ssh user@host "echo 1 2 | awk '{print \$2}'"

although the shell escaping you require will depend slightly
on the shell you are using.

--
Andrew Gabriel
[email address is not usable -- followup in the newsgroup]

Thank you very much Andrew. It worked !!!!

In fact i was using the command - ssh user@host "echo 1 2 | awk
'{print $2}'" before i tried the command using the HERE tag.

Still, i'm trying to figure out why it works correctly when the AWK
command is put in a file and given as input to ssh without any escape
sequence.


heh, let me know if you find a way to do that.

passing $ chars with ssh is a fucking mess.
.