Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to figure out a way to do this for a few hours now, and am having no luck.

I have a large environment file that I have saved as a ksh script. This script works perfect if I type . ./

However, what I'm trying to do is use either ssh or rsh to log on to a remote system, execute this script, then allow me to use the system in it's modified form. I am able to successfully execute the script, but the connection always closes after execution. I would like to be able to keep this connection open.

Any idea on how I can do this?

At the moment, it does not matter if I use SSH or RSH to accomplish this. RSH is preferable. I am using a variety of Linux and Solaris operating systems, so a catch-all method would be nice.

A command like this:
ssh user@host "/home/me/directory/"

Does in fact execute the script on the remote machine, but does not allow me to use the modified environment.

Thanks, Matt

share|improve this question
up vote 1 down vote accepted
ssh -t -t user@host 'bash -l -i --init-file'

The -t -t is to force ssh to allocate a TTY, and the bash -l -i part is to start bash in login-mode and interactively.

The --init-file part is how your script manipulates the environment. It should source ~/.bashrc and /etc/bash.bashrc as well.

share|improve this answer

Maybe you can manually run shell after you're done with your script.

ssh ip -l root "/bin/bash; /bin/bash"
share|improve this answer

Or simply edit your .bash_profile and add the ./ command.

share|improve this answer

If I understand you correctly (and I'm not sure I do), then you simply do this with the "source" command.

ssh to the target machine, and "source ; nextcommand ; nextcommand"

Does that make sense?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.