this is not a problem related to shell script , this a problem on how to restart or use pm2 commands from spawn process in nodejs from a remote server. running the pm2 commands solo or in a shell script directly on the server , it works fine , but when i use spawn i get the error below.
how to restart pm2, using spawn process , using ssh root@ip
i've tried this
ssh root@ip 'pm2 restart all'
but when i try this on my local pc directly from my terminal
it works , but when i try to run it in exces or spawn process , i get this error bash: pm2: command not found failed with code 127
i also tried , putting my commands in script.sh
and send it with this command from spawn
scp /root/script.sh root@${ip}:/root&&ssh root@${ip} bash script.sh
i get the same error. but if i run alone in terminal it works , is the error in environment variable , it's not loaded correctly when i run it in spawn prcess.