Remote host - execute post login commands

Hi,

I am trying to do something like this:


ssh -X me@remotehost
sleep 1
cd profiles
source myenv
clear

After it logs in I want it to set up a large set of environment variables. I do this by sourcing a profile (called myenv above). I thought I could put this all into a shell script. The problem is that it tries to run the commands on the local host rather than the remote host, after it logs in. Is it possible to send these commands to the remote host?

Any ideas?
/jlar

Hi,

ssh allows executing commands direct on the remote host, for example you can do:


ssh me@somehost "ls -l; whoami"

Maybe it is sufficient to put the commands in a separate file and dump/append it to the ssh command.

Hope this helps

You can pass a command to execute as the last parameter of the ssh. Typically, ssh executes the login shell (generally it is /bin/bash) for the logged in user but this can be altered to do what you want. You can have bash with custom profile loaded for you.

why not just source the file containing your variables in .bashrc and .bash_profile? just append the following to your ~/.bashrc and ~/.bash_profile


. ~/myenv

replacing “~/myenv” with the path to your profile

The best way I think would be to create a new profile in Konsole and put in ssh -X me@remotehost… The profiles don’t seem to do anything though.

I would change the .bashrc but that would that not hard code the login to a particular host…? I need to login to lots of different boxes: Solaris/HP-Ux…

/jlar