crontab -e
00 00 * * * /home/username/run.sh >> /home/username/log 2>&1
Inside run.sh:
source /home/username/.bashrc
java
When crontab job is triggered, I got this error in the log:
/home/username/run.sh: 1: /home/username/run.sh: java: not found
However, java path is set in /home/username/.bashrc, so I was expecting sourcing should set the java path:
I know I can fix it by:
export PATH="/usr/local/jdk1.8.0_231/bin:$PATH"
java
But why sourcing .bashrc is not enough? What environment variables does crontab have exactly and what does source .bashrc do exactly (so that crontab doesn't take it into account)?
Thanks.
man 5 crontabcase $- in... for example)?cronexecutes scripts usually withsh.shis usually notbash.shknows nothing aboutsource. I suggest to add a shebang withbashin/home/username/run.shor run/home/username/run.shwithbash.