I have a cronjob very simple:
#! /bin/bash -l
ps cax | grep PM2
if [ $? -eq 0 ]; then
echo $(date -u) - "PM2 is running."
else
echo $(date -u) - "Restarting PM2."
cd ~/public_html/
/home/test/.nvm/versions/node/v10.21.0/bin/pm2 start index.js
fi
The problem appears when my hosting updates the node, and path has change in:
/home/test/.nvm/versions/node/v10.22.0/bin/pm2
and of course the cron fails to run the command. It's there a way to dynamically get that new version folder name?