0

I'm trying to run a command at certain intervals.

pm2 restart appname

Doing this myself works. Then I add it to a bash script.

#!/bin/bash
pm2 restart appname

Running the bash script works: bash scriptname.sh

Then I add it to my crontab:

* * * * * /usr/local/crontab-scripts/scriptname.sh >> /var/log/cronlog.log 2>&1

This gives me the error:/usr/local/crontab-scripts/scriptname.sh: line 4: pm2: command not found

I'm not doing any of this as root, I have pm2 globally installed, I put into my script whereis pm2 and it logged the correct path /usr/local/bin/pm2. Then I tried having my script cd to that path before running pm2, no difference.

I'm out of ideas here.

0

1 Answer 1

2

When you call applications or commands from within scripts or CRON jobs, it helps to spell out the entire path of the application.

In your case I would try re-writing your script to:

#!/bin/bash
/usr/local/bin/pm2 restart appname

However, this seems like overkill and you might as well just call pm2 directly from your crontab:

* * * * * /usr/local/bin/pm2 restart appname >> /var/log/cronlog.log 2>&1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.