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?
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?
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.
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 – 2015-11-30T12:49:16.110
@EladKuzy Could you give me a detailed example of a command that does not work? I mean, the exact command you tried. – MariusMatutiae – 2015-11-30T13:23:01.427
Check the last trigger I added http://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 – 2015-12-01T08:37:36.220
Nothing seems to work? What have you tried so far? – scai – 2015-11-30T11:51:58.317
Well, I have this trigger in the profile: http://imgur.com/2Zu74my When I run in the shell echo test the command doesn't trigger.
– Elad Kuzy – 2015-11-30T12:14:37.587If you're on a Unix system you can run
ssh root@MachineB 'bash -s' < local_script.sh
to run the contents oflocal_script.sh
after connecting toMachineB
. – pzkpfw – 2015-11-30T12:45:57.473