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?
$!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/…