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

Adam Thomas adam.lloyd at gmail.com
Thu Apr 14 23:59:24 MDT 2011


On 15 April 2011 15:46, Carlo Hamalainen <carlo.hamalainen at gmail.com> wrote:
> On Fri, Apr 15, 2011 at 3:37 PM, Adam Thomas <adam.lloyd at gmail.com> wrote:
>>> $ ssh someone at remotebox
>>> $ source lots_of_dev_variables.sh
>>> $ cd /projects/blah/blah/blah
>>> (then I do stuff in the shell)
>>
>> You could add the 2nd two steps to your .bash_profile (on the remote
>> box), which will mean that they get run when you login.
>
> Since various people work on this account, I'd need the remote box's
> bash_profile identify that it is indeed me logging in via ssh. Is that
> possible?

If you're the only one that logs into that machine using the 'someone'
user account you can put it in '/home/someone/.bash_profile'. If
that's not the case then things get a bit tricker.

If you normally login from the same IP (and you're the only one that
logs in with that IP) you can test the SSH_CONNECTION environment
variable.

if [ "`echo $SSH_CONNECTION | cut -f1 -d' '`" = "your_ip_here" ]; then
  source lots_of_dev_variables.sh
  cd /projects/blah/blah/blah
fi

>
> --
> Carlo Hamalainen
> http://carlo-hamalainen.net
>


More information about the linux mailing list