ssh with sed, problems

ssh with sed, problems

am 03.10.2007 19:57:02 von peter sands

Hi,
This script works on the local unix side, it appends:

# !/bin/sh
sed '/Logger/i\
WAC' /opt/db/ge.txt

However if I try to run this via an here doc script using ssh it
errors out:

# !/bin/sh
ssh -T -t -l root parhost< sed '/Logger/i\
WAC' /opt/db/ge.txt
heredoc

returns:
sed: 0602-404 Function /Logger/iWAC cannot be parsed.


Any idea's why ?
Thanks
Pete

Re: ssh with sed, problems

am 03.10.2007 20:10:39 von Icarus Sparry

On Wed, 03 Oct 2007 10:57:02 -0700, peter sands wrote:

> Hi,
> This script works on the local unix side, it appends:
>
> # !/bin/sh
> sed '/Logger/i\
> WAC' /opt/db/ge.txt
>
> However if I try to run this via an here doc script using ssh it errors
> out:
>
> # !/bin/sh
> ssh -T -t -l root parhost< > sed '/Logger/i\
> WAC' /opt/db/ge.txt
> heredoc
>
> returns:
> sed: 0602-404 Function /Logger/iWAC cannot be parsed.
>
>
> Any idea's why ?
> Thanks
> Pete

Yes. 'ssh' gives the command to the remote shell to be executed. However
you have alread done a layer of interpretation on it by your use of a
"heredoc". This does a number of things, like expand shell variables. In
your case the problem is that it also removes backslash newline pairs.

You can see this more clearly if you do

cat < sed '/Logger/i\
turnip'
heredoc

and you will see

sed '/Logger/iturnip'

If you suppress the layer of interpretation, by quoting the first
heredoc, e.g.

cat <<'heredoc'
sed '/Logger/i\
turnip'
heredoc

you get the correct result.

sed '/Logger/i\
turnip'

The same fix should apply to your ssh problem.

Re: ssh with sed, problems

am 04.10.2007 19:08:45 von Michael Tosch

peter sands wrote:
> Hi,
> This script works on the local unix side, it appends:
>
> # !/bin/sh
> sed '/Logger/i\
> WAC' /opt/db/ge.txt
>
> However if I try to run this via an here doc script using ssh it
> errors out:
>
> # !/bin/sh
> ssh -T -t -l root parhost< > sed '/Logger/i\
> WAC' /opt/db/ge.txt
> heredoc
>
> returns:
> sed: 0602-404 Function /Logger/iWAC cannot be parsed.
>
>

You heredoc is parsed twice - once by the local /bin/sh,
and another time by the remote sh.

If you want to bypass an extra shell run,
you simply pass the normal local script to the remote sh:

ssh -T -t -l root parhost /bin/sh < local_script.sh


--
Michael Tosch @ hp : com