[clug] ssh to box, run shell command, then leave shell open?

Kevin Pulo kev at pulo.com.au
Wed May 4 18:09:43 MDT 2011

On Mon, Apr 18, 2011 at 10:00:42AM +1000, Carlo Hamalainen wrote:

> Hal wrote:
> > At the risk of appearing silly...
> >
> > ssh foo at bar.whatever "source /some/script.sh && /bin/bash --login -i"
> Unfortunately doesn't leave me with a shell containing the environment
> variables set in script.sh.

I would have thought that the simplest solution along these lines is

    ssh -t foo at wherever bash --rcfile .bash_special

which will log in (with a tty, so -i isn't needed), and then source
.bash_special out of the remote account's home directory.

The only catch is that you then can't pass -l (--login) to bash,
because it doesn't source .bashrc (or --rcfile) for login shells.  But
this is easily fixed by making the first (or last) thing done by
.bash_special be "source ~/.bash_profile" or similar.


Kevin Pulo
kev at pulo.com.au
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/linux/attachments/20110505/ec1f0e95/attachment.pgp>

More information about the linux mailing list