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 crontab
case $- in
... for example)?cron
executes scripts usually withsh
.sh
is usually notbash
.sh
knows nothing aboutsource
. I suggest to add a shebang withbash
in/home/username/run.sh
or run/home/username/run.sh
withbash
.