-1

My shell script is run over SSH this way:

ssh -i mycert.pem [email protected] <<SSHBLOCK
pm2 logs --lines 100 &
pid=$!
sleep 3
kill $pid
SSHBLOCK

The script works as expected when on local server (not wrapped in sshblock). But when I need to get logs on remote server, $pid is just blank. Why is $! empty when used in the SSHBLOCK above?

1
  • 2
    Hint: Where is $! being expanded? In the local shell, where the heredoc is created, or the remote shell, where the heredoc contents are executed? stackoverflow.com/questions/4937792/… Commented Jul 10, 2017 at 8:19

1 Answer 1

1

You must use a quote '' or escape \ to expand the variable remotely.So,use the here document <<'SSHBLOCK' OR <<\SSHBLOCK

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.