Ever want to run oracle’s sqlplus with crontab? Most of the time, the script won’t be executed, even though you’re already using the right user account. This is because crontab does not source the user’s environment variable when executing the command, and this cause some specific ORACLE variables not having the correct vaules, and in turn caused sqlplus to be unable to find some files required to run.
To solve this, you need to source the environment variables on your script. This is how the crontab script looks like :
$ more gstat.sh
and gstatsql.sh contains the sqlplus command that I want to run, while the gstat.sh is the one called by crontab. This is how my crontab looks like :
30 19 * * * /scripts/gstat.sh
With this, crontab will source the environment variables for the user oracle, and sqlplus will be able to run correctly.