Crond and Environment Variables
Problem description:
Write an exp script and place it in oracle's crontab, but it cannot be executed.
Cause
Crond does not load the user's. profile and. bashrc files by default. Its execution environment only has some basic environment variables, so exp commands cannot be executed because they cannot be found.
Verification process
Write a script and grant the 777 permission to [root @ DBBANK ~] # Cat/tmp/wjf/env | wall
Add this script to the scheduled tasks of the root and oracle users respectively.
[root@DBBANK ~]# whoamiroot[root@DBBANK ~]# crontab -l01 * * * * /tmp/wjf/env[root@DBBANK ~]#
[oracle@DBBANK ~]$ whoamioracle[oracle@DBBANK ~]$ crontab -l02 * * * * /tmp/wjf/env[oracle@DBBANK ~]$
The execution result is
Broadcast message from root@DBBANK (Fri May 8 17:36:02 2015):SHELL=/bin/shUSER=rootPATH=/usr/bin:/bin_=/usr/bin/envPWD=/rootHOME=/rootSHLVL=2LOGNAME=root
[oracle@DBBANK ~]$ Broadcast message from oracle@DBBANK (Fri May 8 17:38:01 2015):SHELL=/bin/shUSER=oraclePATH=/usr/bin:/bin_=/usr/bin/envPWD=/home/oracleHOME=/home/oracleSHLVL=2LOGNAME=oracle
You can see the shell environment opened by crond. There are only some of the most basic environment variables, so you should not think about writing the commands in oracle as scripts in oracle's scheduled tasks. Actually, it cannot.
Solution
Manually export the environment variable in the script.
Or
Source environment variable file at the beginning of the script
Or
. (Space) environment variable File