1

I'm trying to execute some commands on remote host like this :

ssh -t -t -l user 172.20.20.20 <<EOF
  pid=$(ps -ef | grep [a]pp-management | awk '{print $2}') && kill -9 $pid && rm -rf CI/*
EOF

What happens is that I remain logged at remote server and the kill is not executed :

user@ubuntu:~$ pid= && kill -9  && rm -rf CI/*
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

Neither rm gets executed, what am I doing wrong?

I see that nothing get passed to kill -9 command, why is this?

1 Answer 1

2

The expansions introduced by $ signs in the heredoc are evaluated locally, before generating the string that is passed as input to the ssh command.

To avoid this, escape the commands in your heredoc, for instance with quotes around EOF

ssh ... <<"EOF"
3
  • thanks for the response, how do I get back to my current shell, after the command is executed I'm still in the remote server Commented Nov 11, 2013 at 15:26
  • @GandalfStormCrow You can divert ssh command to /dev/null to force it to return to your current shell after issuing the remote command something like this: { sleep 1; YOUR_REMOTE_COMMAND; } >/dev/null &
    – Vombat
    Commented Nov 11, 2013 at 15:55
  • 1
    And if you remove the -t -t ? Any reason why you put them in the first place ? I don't think those commands need a tty. Commented Nov 11, 2013 at 16:09

You must log in to answer this question.

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