Monday, March 14, 2022

[SOLVED] bash script running from cronjob command not found

Issue

my crontab is as follows:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 04 * * * root /home/sphinx_scripts/daily_update_index.sh

daily_update_index.sh is as follows:

indexer  --rotate xxx

now if I run /home/sphinx_scripts/daily_update_index.sh from anywhere(as root), it works fine. But I get emails daily from cron job saying "command indexer is not found". the full path of the indexer is /usr/loca/bin/indexer. Why would I get such an error?


Solution

The issue is that indexer is not on the path. You say it is /usr/local/bin/indexer and you have PATH=/sbin:/bin:/usr/sbin:/usr/bin
To fix this I would put the whole path to indexer in daily_update_index.sh or add /usr/local/bin to the path in daily_update_index.sh



Answered By - mmmmmm
Answer Checked By - Candace Johnson (WPSolving Volunteer)