My shell script is run over SSH this way:
ssh -i mycert.pem email@example.com <<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?