help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] [newbie] non-interactive non-login bash shell


From: Bob Proulx
Subject: Re: [Help-bash] [newbie] non-interactive non-login bash shell
Date: Thu, 10 Mar 2016 17:56:24 -0700
User-agent: Mutt/1.5.24 (2015-08-30)

Divya Thaluru wrote:
> I want to source /etc/profile automatically if I execute a command through
> ssh, which is non-interactive and non login shell. Is there a way to
> achieve this? I really appreciate your help.
> 
> ssh  address@hidden 'echo "import os; print os.environ;" | python'

What is in /etc/profile that is required?  There should be so little
there that it doesn't matter.

I prefer to pipe commands into the remote side of the ssh connection.
Because I live in a very heterogeneous environment.  Different systems
have different shells and different default options.  Therefore
forcing the remote side to be an explicit thing makes it simpler.

  echo '. /etc/profile;. ~/.bashrc;echo "import os; print os.environ;" | 
python' | ssh address@hidden /bin/bash

That rather makes everything very explicit and under your control.  It
doesn't matter if the remote end defaults to different shells (zsh,
ksh, or bash, or whatever) as the program called is explicitly bash.
Then it doesn't matter with what options bash was compiled as this
will explicitly tell bash to source the /etc/profile and ~/.bashrc if
that is what you want.

Normally I would have simpler commands there.

  echo '$HOME/bin/myprog' | ssh address@hidden /bin/bash

And then do all of the setup I need in ~/bin/myprog.

Of course this does take over stdin for this purpose of feeding input
to the remote shell.  For me most of the time this is fine.  If it
isn't then I deal with those cases the hard way.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]