Oracle用户的crontab可以运行,但是发现oracle用户无法对其进行修改。
尝试通过crontab –e的方式修改crontab的配置,在保存的时候报错:
/app/oracle10g/rman_catalog_dmp> crontab -l 40 14 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh /app/oracle10g/rman_catalog_dmp> crontab -e "/var/tmp/aaaa01943" 1 line, 59 characters 47 14 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh ~ ~ ~ ~ "/var/tmp/aaaa01943" 1 line, 59 characters crontab: can't create your crontab file in the crontab directory. /app/oracle10g/rman_catalog_dmp> crontab -l 40 14 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh |
建立一个crontab文件,采用crontab crontab_file的方式同样出现错误:
/app/oracle10g/rman_catalog_dmp> vi crontab.oracle "crontab.oracle" 1 line, 59 characters 47 14 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh ~ ~ "crontab.oracle" 1 line, 59 characters /app/oracle10g/rman_catalog_dmp> crontab crontab.oracle crontab: error IN message queue OPEN, errno=13 warning: commands will be executed USING /usr/bin/sh |
通过GOOGLE查询发现,这个问题有很多人碰到了,可惜的是,没有找到一个合理的解释也没有一个靠谱的解决方法。
由于在网上找不到解决方法,只好自己想办法解决,尝试使用root来设置oracle的crontab,结果这次没有报错,而且EXP脚本也成功运行了:
acap3#[/]crontab -e oracle "/var/tmp/aaaa02394" 1 line, 59 characters 0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh ~ ~ ~ ~ "/var/tmp/aaaa02394" 1 line, 57 characters warning: commands will be executed USING /usr/bin/sh acap3#[/]crontab -l oracle 0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh |
切换到oracle用户,在导出结束后收到mail通知:
/app/oracle10g/rman_catalog_dmp> more /app/oracle10g/rman_catalog_dmp/exp_by_date.sh export ORACLE_SID=RMANDB export ORACLE_BASE=/app/oracle10g export ORACLE_HOME=$ORACLE_BASE/product/10.2.0 export NLS_LANG=American_America.ZHS16CGB231280 export PATH=$ORACLE_HOME/bin:$PATH DATE=`date +"%Y%m%d"` EXP parfile=/app/oracle10g/rman_catalog_dmp/EXP.par file=/app/oracle10g/rman_catalog_dmp/rman_catalog_$DATE.dmp log=/app/oracle10g/rman_cat alog_dmp/rman_catalog_$DATE.log you have mail IN /var/mail/oracle > mail FROM root@acap3 Thu Aug 18 15:21:46 EAT 2011 Received: (FROM root@localhost) BY acap3 (8.9.3 (PHNE_35950)/8.9.3) id PAA02370 FOR oracle; Thu, 18 Aug 2011 15:21:45 +0800 (EAT) DATE: Thu, 18 Aug 2011 15:21:45 +0800 (EAT) FROM: root@acap3 Message-Id: <201108180721.PAA02370@acap3> Subject: cron Export: Release 10.2.0.4.0 - Production ON Thu Aug 18 15:15:00 2011 Copyright (c) 1982, 2007, Oracle. ALL rights reserved. Connected TO: Oracle DATABASE 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production WITH the Partitioning, DATA Mining AND REAL Application Testing options Export done IN ZHS16CGB231280 CHARACTER SET AND AL16UTF16 NCHAR CHARACTER SET About TO export specified users ... . exporting pre-schema PROCEDURAL objects AND actions . exporting FOREIGN FUNCTION library names FOR USER RMAN_FGMS . exporting FOREIGN FUNCTION library names FOR USER RMAN_MODDB . exporting FOREIGN FUNCTION library names FOR USER RMAN_ACDB . . . . exporting post-schema PROCEDURAL objects AND actions . exporting statistics Export TERMINATED successfully WITHOUT warnings. ************************************************* Cron: The previous message IS the standard output AND standard error OF one OF your crontab commands: /app/oracle10g/rman_catalog_dmp/exp_by_date.sh ? q |
这种办法虽然可以解决问题,但是同样也存在一个问题,就是oracle用户没有权限检查自己用户下的crontab设置了。
最后尝试在metalink中查询,没想到找到了最终的解决方案,文档参考ID 1005095.1。导致问题的原因是由于/usr/bin/crontab命令的权限不对:
acap3#[/]crontab -r oracle acap3#[/]ls -l /usr/bin/crontab -rwxrwxrwx 1 root bin 28672 Jul 18 2002 /usr/bin/crontab acap3#[/]chmod 4555 /usr/bin/crontab acap3#[/]ls -l /usr/bin/crontab -r-sr-xr-x 1 root bin 28672 Jul 18 2002 /usr/bin/crontab |
将crontab命令的权限修改为4555后,oracle用户的crontab恢复正常:
/app/oracle10g/rman_catalog_dmp> crontab -e "/var/tmp/aaaa02482" # 0 0 * * * test.sh ~ ~ ~ "/var/tmp/aaaa02482" 1 line, 20 characters warning: commands will be executed USING /usr/bin/sh /app/oracle10g/rman_catalog_dmp> more crontab.oracle 47 14 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh /app/oracle10g/rman_catalog_dmp> echo "0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh" > crontab.oracle /app/oracle10g/rman_catalog_dmp> more crontab.oracle 0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh /app/oracle10g/rman_catalog_dmp> crontab crontab.oracle warning: commands will be executed USING /usr/bin/sh |
从这个问题的解决过程也可以看出,Oracle的metalink知识库的强大之处,一个操作系统上的问题,在HP以及一些操作系统相关的专业网站上都查找不到,反而在Oracle的metalink中查询到了。