Start command inside xterm with login shell, over SSH?

0

1

I'm trying to use ssh to remotely start an xterm that runs a command inside a non-interactive login environment with a file that sets up the environment that is in a non-standard location. Anybody know how?

Joel

Posted 2015-05-27T01:20:39.233

Reputation: 101

Answers

1

There is some missing detail. But (depending on the variety of ssh client and remote system), you would generally use the -X or -Y option to get X-forwarding. The latter is preferred by some, but not necessarily universally available. X11Forwarding (or ForwardX11) may be disallowed by the remote host's sshd daemon. See the ssh manual for some discussion.

Given that, it sounds as if you have in mind something like

ssh -X remotehost xterm -e myshellcommand

Like xterm's -e option, ssh passes the remainder of the line to the remotehost as a command. So there are two levels to work on:

  • "xterm -e myshellcommand"
  • "myshellcommand"

xterm uses execv calls in preference to system, so it can accept (properly escaped or quoted) shell separators such as semicolon without assuming that the parameter value for -e is quoted as a single token.

Semicolon separates commands in the shell. For instance, you might do something like this:

ssh -X remotehost xterm -e ". extraenvironment; cd anotherdirectory; myshellcommand"

You may have to escape the semicolons to make them pass through the different levels, e.g.,

ssh -X remotehost xterm -e '. extraenvironment\; cd anotherdirectory\; myshellcommand'

In a quick check "here" for instance, I found it necessary to also escape the blanks. You will probably have to experiment with your configuration to determine what works with your shell (both local and remote).

Thomas Dickey

Posted 2015-05-27T01:20:39.233

Reputation: 6 891

So that's close, but it still leaves environment variables unset. Basically, I want to source a .bashrc that isn't in a logical place, so I'll need to specify it. Then, I want all the environment variables set in that .bashrc to apply to the "myshellcommand". – Joel – 2015-05-28T02:34:58.527