crontab對oracle操作問題處理

tian1982tian發表於2012-08-17
[root@localhost home]# vi test.sh
#!/bin/sh
ORACLE_HOME=/oracle/ora10/product
export ORACLE_HOME
userpwd=test/test@10.11.0.235:1521/ora10g
$ORACLE_HOME/bin/sqlplus -S $userpwd <alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
INSERT INTO test values(1,'test');
COMMIT;
EOF
exit;
 
以上test.sh檔案中必須設定ORACLE_HOME環境變數,否則加入到crontab 裡不能正常執行(如把環境變數註釋掉:#ORACLE_HOME=/oracle/ora10/product
#export ORACLE_HOME
),即使在sqlplus前加絕對路徑/oracle/ora10/product/bin也不行,crontab檔案如下test1_crond ,日誌見/var/log/cron

[root@localhost cron.d]# vi test1_crond
* * * * *  root sh /home/test.sh  >/home/test.log
~
~
SQL> conn test/test
Connected.
SQL> select * from test;
        ID NAME
---------- --------------------
         1 test
         1 test
         1 test
SQL>

[root@localhost cron.d]# tail -f /var/log/cron
Aug 17 14:03:01 localhost crond[10718]: (root) CMD (sh /home/x.sh)
Aug 17 14:03:01 localhost crond[10720]: (root) CMD (sh /home/test.sh  >/home/test.log)
Aug 17 14:04:01 localhost crond[11102]: (root) CMD (sh /home/x.sh)
Aug 17 14:04:01 localhost crond[11103]: (root) CMD (sh /home/test.sh  >/home/test.log)
Aug 17 14:05:01 localhost crond[11449]: (root) CMD (sh /home/x.sh)
Aug 17 14:05:01 localhost crond[11452]: (root) CMD (sh /home/test.sh  >/home/test.log)

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

相關文章