------------------------- crontab entry contains following
* * * * * /home/app/oracle/sample/sqlcron.sh
------------------------------ sqlcron.sh contains following
/home/app/oracle/sample/sqlconn.sh > /home/app/oracle/sample/sqlslog_$datevar.log
------------------------------ sqlconn.sh contains following
echo "script starting"
date
sqlplus MIS_USER/MIS123 @/home/app/oracle/sample/sqlscr.sh
date
echo "script ending"
------------------------------ sqlscr.sh contains following
analyze table MIS_DIM_CATEGORY compute statistics;
select TO_CHAR(sysdate,'DD-MON-YYYY HH24:MI:SS') as datee from dual;
insert into samp1 values(sysdate);
commit;
exit;
----------------
when i executes sqlcron.sh manually i getting proper out put. But if add sqlcron.sh to crontab file then i am getting following out put only. only bash commands are executing. sql commands are not executing.
script starting
Tue Jun 12 15:51:01 IST 2012
Tue Jun 12 15:51:01 IST 2012
script ending
-----------------------------------------------------------------
What about environment? As cron is not using user's environment, try set important environment variables (ORACLE_HOME,ORACLE_SID,PATH) in your shell script.
Or change the command in crontab to this (assume that you are using "oracle" user):
30 12 * * * /bin/su - oracle -c /home/app/oracle/sample/sqlconn.sh > /home/app/oracle/sample/sqlslog_$datevar.log
i have included environment vars in sqlconn.sh file which are
echo "script starting"
date
export ORACLE_HOME=/home/app/oracle/product/11.2.0/db_1
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus MIS_USER/MIS123 @/home/app/oracle/sample/sqlscr.sh
date
echo "script ending"
then i get correct out put as follows
-----------------------------------------------------------------
script starting
Tue Jun 12 15:58:01 IST 2012
SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 12 15:58:01 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Table analyzed.
DATEE
--------------------
12-JUN-2012 15:58:01
1 row created.
Commit complete.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Tue Jun 12 15:58:01 IST 2012
script ending
-------------------------------------------------------------------------------------------------
No comments:
Post a Comment