1

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

4 Answers 4

1
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.

1

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

ssh ip -l root "/bin/bash env.sh; /bin/bash"
1

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

0

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?

You must log in to answer this question.