HP Unix上oracle呼叫crontab報錯

yangtingkun發表於2011-08-21

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來設定oraclecrontab,結果這次沒有報錯,而且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

從這個問題的解決過程也可以看出,Oraclemetalink知識庫的強大之處,一個作業系統上的問題,在HP以及一些作業系統相關的專業網站上都查詢不到,反而在Oraclemetalink中查詢到了。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-705514/,如需轉載,請註明出處,否則將追究法律責任。

相關文章