Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The best way to accelerate a Macintoy is at 9.8 meters per second per second.


devel / comp.unix.shell / ssh question: How to get both an interactive shell and a program to auto-run?

SubjectAuthor
* ssh question: How to get both an interactive shell and a program to auto-run?Kenny McCormack
+- Re: ssh question: How to get both an interactive shell and aChristian Weisgerber
+- Re: ssh question: How to get both an interactive shell and aChristian Weisgerber
+- Re: ssh question: How to get both an interactive shell and a program to auto-runJavier
`- Re: ssh question: How to get both an interactive shell and a program to auto-runHelmut Waitzmann

1
ssh question: How to get both an interactive shell and a program to auto-run?

<sak1ud$2d07d$1@news.xmission.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: ssh question: How to get both an interactive shell and a program to auto-run?
Date: Sat, 19 Jun 2021 06:13:33 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sak1ud$2d07d$1@news.xmission.com>
Injection-Date: Sat, 19 Jun 2021 06:13:33 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2523373"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 19 Jun 2021 06:13 UTC

I hit this issue today (again), and came up with a solution, but I am
wondering if there is a better or more systematic way to do it.

As we all know, there are basically two ways to invoke "ssh":

1) ssh user@host
and
2) ssh user@host command [arg(s)]

The first gets you an interactive shell, with all the usual trimmings,
while the second gets you a very limited environment to run the one single
command and then exits. There are lots of limitations on the utility of
the second form, such that it is next to useless.

What you would like is to be able to combine the two. That is, get an
interactive login (shell), which then invokes the program you actually want
to run. Note that this can be done with Expect, but let's assume you want
to avoid the overhead/complexity of Expect (at least for the time being).

What you would like is to be able to pass some kind of parameter on the
command line (or in the environment) that the .profile (and/or other
startup file(s)) on the host would recognized and do the right thing with.

The problems are:

1) There is no simple command line option way to do it (AFAIK).
and
2) There is a very short list of environment variables that get passed
down to the remote shell. You can't just make up and pass an
arbitrary variable. One variable that *is* passed is TERM, and
I've figured out a (kludgey, but effective) way to do it using
TERM.

What I seek is a better, less kludgey, way to do it. Is there one?

Also note: it would be really nice, of course, if it didn't require special
code on the host end to make it work...

--
You are again heaping damnation upon your own head by your statements.

- Rick C Hodgin -

Re: ssh question: How to get both an interactive shell and a program to auto-run?

<slrnscs12c.8jl.naddy@lorvorc.mips.inka.de>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: nad...@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: ssh question: How to get both an interactive shell and a
program to auto-run?
Date: Sat, 19 Jun 2021 14:50:52 -0000 (UTC)
Message-ID: <slrnscs12c.8jl.naddy@lorvorc.mips.inka.de>
References: <sak1ud$2d07d$1@news.xmission.com>
Injection-Date: Sat, 19 Jun 2021 14:50:52 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="10092"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Sat, 19 Jun 2021 14:50 UTC

On 2021-06-19, Kenny McCormack <gazelle@shell.xmission.com> wrote:

> As we all know, there are basically two ways to invoke "ssh":
>
> 1) ssh user@host
> and
> 2) ssh user@host command [arg(s)]

There will be some additional details to consider, but in principle
we can ditch ssh and treat this as a shell question. There are
these invocations:

1) sh
2) sh -c 'command [arg(s)]'

> What you would like is to be able to combine the two. That is, get an
> interactive login (shell), which then invokes the program you actually want
> to run.

So, how do you combine the two?

This comes to mind: sh -c 'command; exec sh'

If you're doing this over ssh, you want to tell ssh to allocate a
TTY and possibly ask your shell to behave like a login shell if it
supports a corresponding flag. E.g.:

ssh -t user@host 'command; exec tcsh -l'

> What you would like is to be able to pass some kind of parameter on the
> command line (or in the environment) that the .profile (and/or other
> startup file(s)) on the host would recognized and do the right thing with.

The "ssh command" form does not invoke a login shell, so .profile
won't be sourced. Other startup files may be available.

> 2) There is a very short list of environment variables that get passed
> down to the remote shell. You can't just make up and pass an
> arbitrary variable.

You _can_, see SendEnv and SetEnv in ssh_config(5), but reception
must be permitted with AcceptEnv by the administrator on the server
side, see sshd_config(5).

User ssh keys can be limited to only allow the execution of specified
commands; passing random environment variables potentionally provides
ways to circumvent that restriction.

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: ssh question: How to get both an interactive shell and a program to auto-run?

<slrnscs4k8.8jl.naddy@lorvorc.mips.inka.de>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: nad...@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: ssh question: How to get both an interactive shell and a
program to auto-run?
Date: Sat, 19 Jun 2021 15:51:36 -0000 (UTC)
Message-ID: <slrnscs4k8.8jl.naddy@lorvorc.mips.inka.de>
References: <sak1ud$2d07d$1@news.xmission.com>
Injection-Date: Sat, 19 Jun 2021 15:51:36 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="11371"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Sat, 19 Jun 2021 15:51 UTC

On 2021-06-19, Kenny McCormack <gazelle@shell.xmission.com> wrote:

> As we all know, there are basically two ways to invoke "ssh":
>
> 1) ssh user@host
> and
> 2) ssh user@host command [arg(s)]

There's a historical background to this. It all started with the
Berkeley r-commands:

* rlogin -l user host
... to log into a remote host

* rsh -l user host command
... to execute a command on a remote host

Those were distinct commands. As as shortcut, running

rsh -l user host

would exec() "rlogin -l user host". That feature was already there
in 1982.

The "user@host" alternative form was introduced much later, btw.

ssh was designed as a drop-in replacement for the Berkeley
rlogin/rsh/rcp suite, so it came with the slogin, ssh, and scp
commands, respectively. Just like rsh without a command invoked
rlogin, ssh without a command would effectively perform slogin.
Contrary to rsh and rlogin, ssh/slogin were just different names
for one and the same exectuable, though.

Over time, the slogin form of the command fell into disuse and was
increasingly forgotten. OpenSSH removed the slogin link to no
fanfare in November 2015.

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: ssh question: How to get both an interactive shell and a program to auto-run?

<_s-dnXmV0oNbtFP9nZ2dnUU78UPNnZ2d@brightview.co.uk>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 19 Jun 2021 12:30:46 -0500
From: inva...@invalid.invalid (Javier)
Subject: Re: ssh question: How to get both an interactive shell and a program to auto-run?
Newsgroups: comp.unix.shell
References: <sak1ud$2d07d$1@news.xmission.com>
Message-ID: <_s-dnXmV0oNbtFP9nZ2dnUU78UPNnZ2d@brightview.co.uk>
Date: Sat, 19 Jun 2021 12:30:46 -0500
Lines: 57
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-YYn2JmV9SQVaEkcZL/D/F2eR4AIb8J7861CJmg6hjKw3eMWLdxxenBErdotBrrV1iXJnAsKxF7kBDEs!T4IIzx1qpxrLxWsHBzALdEujUiZXgeBTTGmxGtQ4+fg36DtZoG8gP1ACqC01mkyxujzicV24grNE!hX+vFvLeLcuGwFTkwJ9mRtSxFw==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3094
 by: Javier - Sat, 19 Jun 2021 17:30 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:
> I hit this issue today (again), and came up with a solution, but I am
> wondering if there is a better or more systematic way to do it.
>
> As we all know, there are basically two ways to invoke "ssh":
>
> 1) ssh user@host
> and
> 2) ssh user@host command [arg(s)]
>
> The first gets you an interactive shell, with all the usual trimmings,
> while the second gets you a very limited environment to run the one single
> command and then exits. There are lots of limitations on the utility of
> the second form, such that it is next to useless.
>
> What you would like is to be able to combine the two. That is, get an
> interactive login (shell), which then invokes the program you actually want
> to run. Note that this can be done with Expect, but let's assume you want
> to avoid the overhead/complexity of Expect (at least for the time being).
>
> What you would like is to be able to pass some kind of parameter on the
> command line (or in the environment) that the .profile (and/or other
> startup file(s)) on the host would recognized and do the right thing with.

This is a bit more complex than Christian Weisgerber solution,
but has the advantage of being able to define shell functions,
which would be lost with 'exec bash -l'

Most interpreted languages have a feature to execute commands at
interpreter startup befaure it going interactive. In bash it's
done with --rcfile

bash --rcfile <(echo '
some_command;
' )

I use the non-posix bash feature of process substitution <(...) to
avoiding creating an extra file.

Note that when using the --rcfile option ~/.bashrc is not sourced
automatically, so you may want to source it explicitely.

bash --rcfile <(echo '
. ${HOME}/.bashrc;
some_command;
' )

For ssh

ssh -t user@host 'bash --rcfile <(echo "
. ${HOME}/.bashrc;
some_command;
")'

As Christian Weisgerber says bash invoked that way will not be
considered as a login shell so you may also want to source explicitly
/etc/profile ~/.bash_profile, ~/.bash_login, and ~/.profile.

Re: ssh question: How to get both an interactive shell and a program to auto-run?

<835yy95qfp.fsf@helmutwaitzmann.news.arcor.de>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!wEBswI28Vra6OQC/BnHlFA.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: ssh question: How to get both an interactive shell and a program to auto-run?
Date: Sun, 20 Jun 2021 02:29:30 +0200
Organization: Aioe.org NNTP Server
Lines: 44
Message-ID: <835yy95qfp.fsf@helmutwaitzmann.news.arcor.de>
References: <sak1ud$2d07d$1@news.xmission.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: wEBswI28Vra6OQC/BnHlFA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
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
Cancel-Lock: sha1:rFIs8XCk7Rn1TlFg5oBpG9s00Zs=
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 - Sun, 20 Jun 2021 00:29 UTC

gazelle@shell.xmission.com (Kenny McCormack):

>I hit this issue today (again), and came up with a solution, but I
>am wondering if there is a better or more systematic way to do it.
>
>As we all know, there are basically two ways to invoke "ssh":
>
> 1) ssh user@host
>and
> 2) ssh user@host command [arg(s)]
>
>The first gets you an interactive shell, with all the usual
>trimmings, while the second gets you a very limited environment to
>run the one single command and then exits. There are lots of
>limitations on the utility of the second form, such that it is next
>to useless.
>
>What you would like is to be able to combine the two. That is, get
>an interactive login (shell), which then invokes the program you
>actually want to run.

If your goal is to get a full environment (like a login shell does)
but then just execute one (non‐interactive) commandline rather than
becoming interactive, let the remote shell “exec” a bash, which
will “exec” a non‐interactive login shell, which will be given a
commandline to invoke the program you actually want to run:

ssh -- user@host \
'exec bash -c -- '\''"$@"'\'' bash exec -l --' \
'"$SHELL" -c -- '\''"$@"'\'' "${SHELL##*/}"' \
'program with arguments'

If your remote shell is a bash (or precisely a shell, which knows of
the “-l” option of the “exec” built‐in command, see the bash manual
page), the command can be simplified to be

ssh -- user@host \
'exec -l --' \
'"$SHELL" -c -- '\''"$@"'\'' "${SHELL##*/}"' \
'program with arguments'

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor