Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 . ./setEnv.sh

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/setEnv.sh"

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
add comment

4 Answers

up vote 1 down vote accepted
ssh -t -t user@host 'bash -l -i --init-file env.sh'

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
add comment

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

ssh ip -l root "/bin/bash env.sh; /bin/bash"
share|improve this answer
add comment

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

share|improve this answer
add comment

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 env.sh ; nextcommand ; nextcommand"

Does that make sense?

share|improve this answer
add comment

Your Answer

 
discard

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