I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:
ssh -o StrictHostKeyChecking=no -i /Path/to/key-pair.pem ubuntu@${ec2ips[i]} 'bash ' << 'STARTAPP'
cd ~/my-app-folder
pm2 start ./bin/www --name 'my-app'
exit
STARTAPP
when I ssh in normally, all pm2 commands run fine. If I ssh in and run a script with pm2 in it, it also works as expected. It's only when I try and run it on a remote machine from my machine.