Crontab doesnt execute bash profile.....check below errors and then solution with examples......
I have created a bash script rakesh.sh
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!bin/bash
export DATE=$(date +"%m_%d_%y_%H:%M:%S_%p")/u01/app/oracle/product/10.2.0/db_1/bin/exp rakesh/rakesh@rockdb file=/home/oracle/backups/rakesh$DATE.dmp log=/home/oracle/backups/rakesh$DATE.log statistics=none
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The script is runing perfectly fine from commandline. ./rakesk.sh
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[oracle@oraclelinux bin]$ crontab -e SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=oracle
HOME=/
*/5 * * * * sh /home/oracle/rakesh.sh
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The above crontab command is failed when we check the /var/spool/mail/oracle file, the log file says:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Invalid format of Export Utility name
verify that ORACLE_HOME is properly set
Export terminiated unsuccessfully
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Solution: CRON does not execute .bash_profile or .profile. We need to set environment variables in the script. I have modified the script as below, and now its working fine, runing every five minutes..
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/bin/bash
export ORACLE_SID=db
export PATH=$PATH:/usr/local/bin
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
export DATE=$(date +"%m_%d_%y_%H:%M:%S_%p")/home/oracle/oracle/product/10.2.0/db_1/bin/exp rakesh/rakesh@rockdb file=/home/oracle/backups/test$DATE.dmp log=/home/oracle/backups/test$DATE.log statistics=none
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Now its working :) :)
Thursday, June 24, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment