Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Power is danger. -- The Centurion, "Balance of Terror", stardate 1709.2


devel / comp.unix.shell / Re: Pass the locally set variable to remote host.

SubjectAuthor
* Pass the locally set variable to remote host.hongy...@gmail.com
`* Re: Pass the locally set variable to remote host.Helmut Waitzmann
 +* Re: Pass the locally set variable to remote host.Grant Taylor
 |`* Re: Pass the locally set variable to remote host.hongy...@gmail.com
 | `* Re: Pass the locally set variable to remote host.Janis Papanagnou
 |  `* Re: Pass the locally set variable to remote host.hongy...@gmail.com
 |   +* Re: Pass the locally set variable to remote host.Janis Papanagnou
 |   |+* Re: Pass the locally set variable to remote host.Grant Taylor
 |   ||`* Re: Pass the locally set variable to remote host.Janis Papanagnou
 |   || `- Re: Pass the locally set variable to remote host.Eric Pozharski
 |   |`- Re: Pass the locally set variable to remote host.hongy...@gmail.com
 |   `- Re: Pass the locally set variable to remote host.William Unruh
 `- Re: Pass the locally set variable to remote host.Helmut Waitzmann

1
Pass the locally set variable to remote host.

<1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3630&group=comp.unix.shell#3630

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7747:: with SMTP id g7mr33922346qtu.144.1618383056627;
Tue, 13 Apr 2021 23:50:56 -0700 (PDT)
X-Received: by 2002:a05:622a:100f:: with SMTP id d15mr5195906qte.2.1618383056404;
Tue, 13 Apr 2021 23:50:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 13 Apr 2021 23:50:56 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=211.23.211.40; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 211.23.211.40
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
Subject: Pass the locally set variable to remote host.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 14 Apr 2021 06:50:56 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Wed, 14 Apr 2021 06:50 UTC

See my following testing:

<quote>
$ env aa=bb ssh -T -p2101 werner@pve.hyddns.xyz << \EOF
var=`pwd`
echo var=$var
echo aa=$aa
EOF
werner@pve.hyddns.xyz's password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-48-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

44 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
*** System restart required ***
var=/home/werner
aa=
</quote>

Why can't the locally set variable be passed to the remote host?

Regards,
HY

Re: Pass the locally set variable to remote host.

<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3643&group=comp.unix.shell#3643

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!wVWNghiHzLvgUGWCM9zeZQ.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 00:37:54 +0200
Organization: Aioe.org NNTP Server
Lines: 8
Message-ID: <8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: wVWNghiHzLvgUGWCM9zeZQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Copies-To: nobody
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:/idj5DNOcHhm8tenj0vxIusReH8=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Wed, 14 Apr 2021 22:37 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com>:

>Why can't the locally set variable be passed to the remote host?
>

Because a 'ssh' command does not pass any locally set variables to
the remote host.  You'll have to send a variable assignment command
to the remote host, to let the remote shell set that variable. 

Re: Pass the locally set variable to remote host.

<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3646&group=comp.unix.shell#3646

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Wed, 14 Apr 2021 20:58:42 -0600
Organization: TNet Consulting
Message-ID: <s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 15 Apr 2021 02:59:37 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="11458"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.9.0
In-Reply-To: <8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
Content-Language: en-US
 by: Grant Taylor - Thu, 15 Apr 2021 02:58 UTC

On 4/14/21 4:37 PM, Helmut Waitzmann wrote:
> Because a 'ssh' command does not pass any locally set variables to the
> remote host.  You'll have to send a variable assignment command to the
> remote host, to let the remote shell set that variable.

I took HY's comment to be related to the heredoc expanding the variable
before sending things to the remote side to be executed. E.g. local
expansion of the $var and $aa variables as part of the process of
evaluating the heredoc.

My quick testing shows that the following works.

# ssh target << EOF
var=`pwd`
echo var=\$var
echo host=$HOST
echo host=\$HOST
EOF
var=/path/that/my/local/ssh/client/is/in
host=<local host's name>
host=<remote host's name>
#

The back tick is expanded locally thus populating a static value in the
heredoc that's sent to the remote system. The escaped $var is following
an explicit set from data based locally. The unescaped $HOST hast he
local host name. The escaped $HOST shows the remote hosts name.

Maybe I'm misunderstanding HY's question. But I never thought it was
about sending variables as part of the SSH connection's metadata.

--
Grant. . . .
unix || die

Re: Pass the locally set variable to remote host.

<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3647&group=comp.unix.shell#3647

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:12ab:: with SMTP id x11mr2914178qki.294.1618491840564;
Thu, 15 Apr 2021 06:04:00 -0700 (PDT)
X-Received: by 2002:ac8:7e95:: with SMTP id w21mr2891099qtj.244.1618491840348;
Thu, 15 Apr 2021 06:04:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 15 Apr 2021 06:04:00 -0700 (PDT)
In-Reply-To: <s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
Injection-Info: google-groups.googlegroups.com; posting-host=211.23.211.41; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 211.23.211.41
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de> <s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
Subject: Re: Pass the locally set variable to remote host.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 15 Apr 2021 13:04:00 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Thu, 15 Apr 2021 13:04 UTC

On Thursday, April 15, 2021 at 10:58:41 AM UTC+8, Grant Taylor wrote:
> On 4/14/21 4:37 PM, Helmut Waitzmann wrote:
> > Because a 'ssh' command does not pass any locally set variables to the
> > remote host. You'll have to send a variable assignment command to the
> > remote host, to let the remote shell set that variable.
> I took HY's comment to be related to the heredoc expanding the variable
> before sending things to the remote side to be executed. E.g. local
> expansion of the $var and $aa variables as part of the process of
> evaluating the heredoc.
>
> My quick testing shows that the following works.
>
> # ssh target << EOF
> var=`pwd`
> echo var=\$var
> echo host=$HOST
> echo host=\$HOST
> EOF
> var=/path/that/my/local/ssh/client/is/in
> host=<local host's name>
> host=<remote host's name>
> #
>
> The back tick is expanded locally thus populating a static value in the
> heredoc that's sent to the remote system. The escaped $var is following
> an explicit set from data based locally. The unescaped $HOST hast he
> local host name. The escaped $HOST shows the remote hosts name.
>
> Maybe I'm misunderstanding HY's question. But I never thought it was
> about sending variables as part of the SSH connection's metadata.

Thank you very much. You totally understand what I want to do.

See the following testing based on your method:

$ cat script.sh
#!/usr/bin/env bash
cd /tmp
aa=bb

env cc=dd ssh -p2101 werner@pve.hyddns.xyz << EOF
var=`pwd`
echo var=$var
echo var=\$var
echo host=$HOSTNAME
echo host=\$HOSTNAME
echo aa=$aa
echo aa=\$aa
echo cc=$cc
echo cc=\$cc
EOF

$ bash script.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-48-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

46 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
*** System restart required ***
var=
var=/tmp
host=X10DAi
host=Standard-PC-i440FX-PIIX-1996
aa=bb
aa=
cc=
cc=

Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?

Regards,
HY

Re: Pass the locally set variable to remote host.

<s59f2j$lfh$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3650&group=comp.unix.shell#3650

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 15:28:51 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 24
Message-ID: <s59f2j$lfh$1@news-1.m-online.net>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:712c:9e33:9e41:532f
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1618493331 22001 2001:a61:252a:da01:712c:9e33:9e41:532f (15 Apr 2021 13:28:51 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 15 Apr 2021 13:28:51 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
 by: Janis Papanagnou - Thu, 15 Apr 2021 13:28 UTC

On 15.04.2021 15:04, hongy...@gmail.com wrote:
> ...
> env cc=dd ssh -p2101 werner@pve.hyddns.xyz << EOF
> ...
> echo cc=$cc
> echo cc=\$cc
> EOF
>
> ...
> cc=
> cc=
>
>
> Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?

Because it's undefined (on here-doc shell level).
(See 'man env' for details.)

Janis

> Regards,
> HY
>

Re: Pass the locally set variable to remote host.

<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3652&group=comp.unix.shell#3652

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:4752:: with SMTP id k18mr3135181qtp.158.1618494812396;
Thu, 15 Apr 2021 06:53:32 -0700 (PDT)
X-Received: by 2002:a05:620a:21de:: with SMTP id h30mr3463235qka.397.1618494812253;
Thu, 15 Apr 2021 06:53:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 15 Apr 2021 06:53:32 -0700 (PDT)
In-Reply-To: <s59f2j$lfh$1@news-1.m-online.net>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.83.158; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.83.158
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de> <s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com> <s59f2j$lfh$1@news-1.m-online.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
Subject: Re: Pass the locally set variable to remote host.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 15 Apr 2021 13:53:32 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Thu, 15 Apr 2021 13:53 UTC

On Thursday, April 15, 2021 at 9:28:55 PM UTC+8, Janis Papanagnou wrote:
> On 15.04.2021 15:04, hongy...@gmail.com wrote:
> > ...
> > env cc=dd ssh -p2101 wer...@pve.hyddns.xyz << EOF
> > ...
> > echo cc=$cc
> > echo cc=\$cc
> > EOF
> >
> > ...
> > cc=
> > cc=
> >
> >
> > Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?
> Because it's undefined (on here-doc shell level).
> (See 'man env' for details.)

I noticed the following statement:

DESCRIPTION
Set each NAME to VALUE in the environment and run COMMAND.

This should mean that the 'env' command's lifetime/scope is the runtime range/duration for that COMMAND.

HY

Re: Pass the locally set variable to remote host.

<s59k0k$mqb$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3653&group=comp.unix.shell#3653

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 16:53:08 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 39
Message-ID: <s59k0k$mqb$1@news-1.m-online.net>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
<s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:712c:9e33:9e41:532f
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1618498388 23371 2001:a61:252a:da01:712c:9e33:9e41:532f (15 Apr 2021 14:53:08 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 15 Apr 2021 14:53:08 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
 by: Janis Papanagnou - Thu, 15 Apr 2021 14:53 UTC

On 15.04.2021 15:53, hongy...@gmail.com wrote:
> On Thursday, April 15, 2021 at 9:28:55 PM UTC+8, Janis Papanagnou wrote:
>> On 15.04.2021 15:04, hongy...@gmail.com wrote:
>>> ...
>>> env cc=dd ssh -p2101 wer...@pve.hyddns.xyz << EOF
>>> ...
>>> echo cc=$cc
>>> echo cc=\$cc
>>> EOF
>>>
>>> ...
>>> cc=
>>> cc=
>>>
>>>
>>> Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?
>> Because it's undefined (on here-doc shell level).
>> (See 'man env' for details.)
>
> I noticed the following statement:
>
> DESCRIPTION
> Set each NAME to VALUE in the environment and run COMMAND.
>
> This should mean that the 'env' command's lifetime/scope is the runtime range/duration for that COMMAND.

Exactly. And the command in your case is just

ssh -p2101 wer...@pve.hyddns.xyz

but not the subsequent here-doc that is processed in the calling shell's
context.

Janis

>
> HY
>

Re: Pass the locally set variable to remote host.

<s59rb5$lvv$2@tncsrv09.home.tnetconsulting.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3654&group=comp.unix.shell#3654

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 10:57:17 -0600
Organization: TNet Consulting
Message-ID: <s59rb5$lvv$2@tncsrv09.home.tnetconsulting.net>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
<s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
<s59k0k$mqb$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 15 Apr 2021 16:58:13 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="22527"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.9.0
In-Reply-To: <s59k0k$mqb$1@news-1.m-online.net>
Content-Language: en-US
 by: Grant Taylor - Thu, 15 Apr 2021 16:57 UTC

On 4/15/21 8:53 AM, Janis Papanagnou wrote:
> but not the subsequent here-doc that is processed in the calling
> shell's context.

The minutia of what is expanded (or not) when can get quite complex.

If you think shell is complicated, try messing with nested m4. }:-)

--
Grant. . . .
unix || die

Re: Pass the locally set variable to remote host.

<s59t99$vhj$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3655&group=comp.unix.shell#3655

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: unr...@invalid.ca (William Unruh)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 17:31:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <s59t99$vhj$1@dont-email.me>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
<s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
Injection-Date: Thu, 15 Apr 2021 17:31:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8744735b4addb6bc4146ccf4370d75a5";
logging-data="32307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9BpG1lq/fn7HFUyESggEC"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Hu2+irQdEKeVnei5aTqG1iNbkbw=
 by: William Unruh - Thu, 15 Apr 2021 17:31 UTC

On 2021-04-15, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
> On Thursday, April 15, 2021 at 9:28:55 PM UTC+8, Janis Papanagnou wrote:
>> On 15.04.2021 15:04, hongy...@gmail.com wrote:
>> > ...
>> > env cc=dd ssh -p2101 wer...@pve.hyddns.xyz << EOF
>> > ...
>> > echo cc=$cc
>> > echo cc=\$cc
>> > EOF
>> >
>> > ...
>> > cc=
>> > cc=
>> >
>> >
>> > Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?

cc does "take effect"-- for the local program ssh.
And remember that you have to export a variable if you want it to remain
set in a child shell. and it is never exported to a parent.
Also, ssh does not set anything on the remote system. So above you set
cc in the local system for the ssh command. It then starts a session on
the remote syste, and runs the commands on the remote system. But that
local setting of cc is NOT exported to the remote system. That is NOT
now ssh works. You will have to set cc in the remote system if you want
it to be effective on the remote system.

Re: Pass the locally set variable to remote host.

<s5a0kd$qhl$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3656&group=comp.unix.shell#3656

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 20:28:29 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 19
Message-ID: <s5a0kd$qhl$1@news-1.m-online.net>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
<s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
<s59k0k$mqb$1@news-1.m-online.net>
<s59rb5$lvv$2@tncsrv09.home.tnetconsulting.net>
NNTP-Posting-Host: 2001:a61:252a:da01:712c:9e33:9e41:532f
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1618511309 27189 2001:a61:252a:da01:712c:9e33:9e41:532f (15 Apr 2021 18:28:29 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 15 Apr 2021 18:28:29 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <s59rb5$lvv$2@tncsrv09.home.tnetconsulting.net>
 by: Janis Papanagnou - Thu, 15 Apr 2021 18:28 UTC

On 15.04.2021 18:57, Grant Taylor wrote:
> On 4/15/21 8:53 AM, Janis Papanagnou wrote:
>> but not the subsequent here-doc that is processed in the calling
>> shell's context.
>
> The minutia of what is expanded (or not) when can get quite complex.

I think it's quite obvious in the given case once you decompose the
commands in pieces. One (the non-passing of settings by ssh) had been
already answered in the first couple of responses, the other (the
non-setting of the variable in the current shell context) meanwhile
as well.

> If you think shell is complicated, try messing with nested m4. }:-)

I don't even remember *when* I last had to do with m4. :-)

Janis

Re: Pass the locally set variable to remote host.

<831rbbnv6d.fsf@helmutwaitzmann.news.arcor.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3659&group=comp.unix.shell#3659

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!7xZltWbuN2zw65Ruh1HLJQ.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Thu, 15 Apr 2021 22:34:50 +0200
Organization: Aioe.org NNTP Server
Lines: 22
Message-ID: <831rbbnv6d.fsf@helmutwaitzmann.news.arcor.de>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<74037578-30b9-401c-91d4-871b676e9310n@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: 7xZltWbuN2zw65Ruh1HLJQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:LkH5h6+cFiayX66zVbo99txvg34=
Mail-Copies-To: nobody
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Thu, 15 Apr 2021 20:34 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com>:
>On Thursday, April 15, 2021 at 6:44:48 AM UTC+8, Helmut Waitzmann wrote:
>> "hongy...@gmail.com" <hongy...@gmail.com>:

>>> Why can't the locally set variable be passed to the remote host?
>>>
>> Because a 'ssh' command does not pass any locally set variables to
>> the remote host. You'll have to send a variable assignment command
>> to the remote host, to let the remote shell set that variable.
>
>How to do that?
>

If your local as well as the remote shell is a 'bash', you can use
the '%q' format directive of the 'printf' bash built‐in command: 

local='some value' &&
ssh -T -p2101 werner@pve.hyddns.xyz << EOF
remote=$( printf '%q' "$local" )
printf 'variable %s has value %q\\n' remote "\$remote"
EOF

Re: Pass the locally set variable to remote host.

<ce303e8b-2bce-40d1-9337-60c4110a467fn@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3662&group=comp.unix.shell#3662

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:88:: with SMTP id o8mr5419567qtw.39.1618529015718;
Thu, 15 Apr 2021 16:23:35 -0700 (PDT)
X-Received: by 2002:ac8:7557:: with SMTP id b23mr5343326qtr.74.1618529015561;
Thu, 15 Apr 2021 16:23:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer04.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 15 Apr 2021 16:23:35 -0700 (PDT)
In-Reply-To: <s59k0k$mqb$1@news-1.m-online.net>
Injection-Info: google-groups.googlegroups.com; posting-host=211.23.211.40; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 211.23.211.40
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de> <s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com> <s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com> <s59k0k$mqb$1@news-1.m-online.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ce303e8b-2bce-40d1-9337-60c4110a467fn@googlegroups.com>
Subject: Re: Pass the locally set variable to remote host.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 15 Apr 2021 23:23:35 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2553
 by: hongy...@gmail.com - Thu, 15 Apr 2021 23:23 UTC

On Thursday, April 15, 2021 at 10:53:13 PM UTC+8, Janis Papanagnou wrote:
> On 15.04.2021 15:53, hongy...@gmail.com wrote:
> > On Thursday, April 15, 2021 at 9:28:55 PM UTC+8, Janis Papanagnou wrote:
> >> On 15.04.2021 15:04, hongy...@gmail.com wrote:
> >>> ...
> >>> env cc=dd ssh -p2101 wer...@pve.hyddns.xyz << EOF
> >>> ...
> >>> echo cc=$cc
> >>> echo cc=\$cc
> >>> EOF
> >>>
> >>> ...
> >>> cc=
> >>> cc=
> >>>
> >>>
> >>> Why the 'cc' dosen't take effect at all for both escaped and unescaped reference?
> >> Because it's undefined (on here-doc shell level).
> >> (See 'man env' for details.)
> >
> > I noticed the following statement:
> >
> > DESCRIPTION
> > Set each NAME to VALUE in the environment and run COMMAND.
> >
> > This should mean that the 'env' command's lifetime/scope is the runtime range/duration for that COMMAND.
> Exactly. And the command in your case is just
>
> ssh -p2101 wer...@pve.hyddns.xyz
>
> but not the subsequent here-doc that is processed in the calling shell's
> context.

Got it. Thanks again.

HY
>
> Janis
>

Re: Pass the locally set variable to remote host.

<slrns7ij4m.70b.whynot@orphan.zombinet>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=3664&group=comp.unix.shell#3664

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: why...@pozharski.name (Eric Pozharski)
Newsgroups: comp.unix.shell
Subject: Re: Pass the locally set variable to remote host.
Date: Fri, 16 Apr 2021 08:36:38 +0000
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <slrns7ij4m.70b.whynot@orphan.zombinet>
References: <1d8d6b54-da3a-4674-bf3d-7d3169129bf0n@googlegroups.com>
<8335vspk59.fsf@helmutwaitzmann.news.arcor.de>
<s58a6p$b62$1@tncsrv09.home.tnetconsulting.net>
<3f380bac-228c-443f-9a97-5a92e344b0b3n@googlegroups.com>
<s59f2j$lfh$1@news-1.m-online.net>
<776874ed-9c42-47cb-8fb1-69cebb15e9b3n@googlegroups.com>
<s59k0k$mqb$1@news-1.m-online.net>
<s59rb5$lvv$2@tncsrv09.home.tnetconsulting.net>
<s5a0kd$qhl$1@news-1.m-online.net>
Injection-Info: reader02.eternal-september.org; posting-host="895ec7323c61172094f92436e9f4e49b";
logging-data="28638"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MLxPhTRRsGuCnspD7Inkv"
User-Agent: slrn/pre1.0.0-18 (Linux)
Cancel-Lock: sha1:IQBZzpJpkmlIOPk0q3vCyTyG6fc=
 by: Eric Pozharski - Fri, 16 Apr 2021 08:36 UTC

with <s5a0kd$qhl$1@news-1.m-online.net> Janis Papanagnou wrote:
> On 15.04.2021 18:57, Grant Taylor wrote:
>> On 4/15/21 8:53 AM, Janis Papanagnou wrote:

*SKIP*
>> If you think shell is complicated, try messing with nested m4. }:-)
> I don't even remember *when* I last had to do with m4. :-)

Oh, I *remember* -- m4 was fine, surrounding environment wasn't
sustainable :/

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor