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 have a simple problem of needing to execute an export command over ssh, and then stay logged in, but I'm having some trouble. Though I am interested in a solution to this problem for many reasons, the main one is so I can custom set my terminal tabs to a name of my choosing.

Here's the command I have so far:

ssh -t root@somehost "export PROMPT_COMMAND=''; echo -ne '\033]0;MY_TAB_NAME'; echo -ne '\007'; /bin/bash -i"

This is quite a doozy, and I think I am just about there. The -t option opens a pty (pseudo terminal), while the /bin/bash -i opens an interactive bash session (thus staying logged in after ssh command execution. The export command simply clears out the prompt in order for the following echo to rename it.

The problem I'm having is that the export doesn't seem to be executing in the right shell. I think I am missing something pretty simple.

Also, I am trying to make this purely command-line based without having to use the various .bash files. I have hundreds of servers I connect to, and have an easy way to bookmark all the connections, but just need some way to custom name each tab in my terminal (Mac OS X, willing to use iTerm if an easier solution exists).

Thanks!

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Perhaps you should look at using ~/.ssh/environment or the environment option in ~/.ssh/authorized_keys instead. See the sshd(8) man page for details.

share|improve this answer
ssh host -t VAR=VALUE bash --login
share|improve this answer
    
Nice, simple and works. –  SebastianG Feb 25 '13 at 16:16

I have a simple problem of needing to execute an export command over ssh, and then stay logged in [...]

Just to solve your main question, without digging too much in the rest of your problem. If you want to export some variables (or other environment stuff) you can use env.

The env command lets you run a program in a modified environment. Hence you can use it to run bash -i in the remote server modifying the environment at pleasure.

I leave you just one example:

hmontoliu@laptop:~$ ssh -t remoteuser@remoteserver env EXPORTEDSTUFF='foo' MOREXPORTEDSTUFF='bar' bash -i
remoteuser@remoteserver's password: 
remoteuser@remoteserver:~$ echo $EXPORTEDSTUFF 
foo
remoteuser@remoteserver:~$ echo $MOREXPORTEDSTUFF 
bar

Check env's man page

HTH

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.