1

I'm trying to trigger the following command after "ssh somehost": export PROMPT_COMMAND='echo -ne "\033]0;$HOSTNAME\007"'

nothing seems to work, any suggestions?

3
  • Nothing seems to work? What have you tried so far?
    – scai
    Nov 30, 2015 at 11:51
  • Well, I have this trigger in the profile: imgur.com/2Zu74my When I run in the shell echo test the command doesn't trigger.
    – Elad Kuzy
    Nov 30, 2015 at 12:14
  • If you're on a Unix system you can run ssh root@MachineB 'bash -s' < local_script.sh to run the contents of local_script.sh after connecting to MachineB.
    – pzkpfw
    Nov 30, 2015 at 12:45

1 Answer 1

0

I do not think that can be done.

First of all I had to rewrite your command; though this is voided by the fact (see later) that what you wish to obtain cannot be achieved, yet the method to do so is of some interest and generality, so I will discuss it. I had to change your command to

  ssh me@remote 'COLOR=("echo" "-ne" "\"\\033[48;5;95;38;5;214m\$HOSTNAME\033[0m\""); export PROMPT_COMMAND=${COLOR[@]}'

The reason is that it is necessary to prevent the local shell to substitute to $HOSTANME its local value, hence what we pass to the remote server must be wrapped in single quotes, '. For this to work, there must be no single quotes inside the command to pass, so I had to rewrite it in such a way that no single quotes appear in he command to be executed remotely. I managed to do this with an array, COLOR. The command

COLOR=("echo" "-ne" "\"\\033[48;5;95;38;5;214m\$HOSTNAME\033[0m\"") export PROMPT_COMMAND=${COLOR[@]}  

works fine locally (the choice of colors is mine).

There are two ways to export environment variables via ssh. First, one can change the variable AcceptEnv in the server's /etc/ssh/sshd_config file: but the manual states

AcceptEnv

Specifies what environment variables sent by the client will be copied into the session's environ.

The emphasis here is on the session: no global change.

The second way is thru the PermitUserEnvironment variable:

PermitUserEnvironment

Specifies whether ~/.ssh/environment and environment= options in
 ~/.ssh/authorized_keys are processed by sshd.  The default is
 "no".  Enabling environment processing may enable users to bypass
 access restrictions in some configurations using mechanisms such
 as LD_PRELOAD.

As you can see, ssh is quite careful in not allowing a remote user to change global environment variables.

3
  • Thanks for the very informative and deep answer, however, I'm only trying to echo some stuff. Even something very basic doesn't work. For example: trigger-test action-Run Command... Parameters-echo hi doesn't work.
    – Elad Kuzy
    Nov 30, 2015 at 12:49
  • @EladKuzy Could you give me a detailed example of a command that does not work? I mean, the exact command you tried. Nov 30, 2015 at 13:23
  • Check the last trigger I added imgur.com/lkCPmkX . I then in bash test it by entering echo "hi". Other triggers are working, only "Run Command..." action type is giving me troubles.
    – Elad Kuzy
    Dec 1, 2015 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .