クローンジョブが実行されない

クローンジョブが実行されない

Oracle Linux 5.10

oracleユーザーとして "tblspc_usage.sh"スクリプトを手動で正常に実行できます。私にレポートを電子メールで送信したので、私はこれを知っています。

しかし、cronではまったく実行されません。ログファイルを生成しません。

[oracle@dub-ImrORA3 scripts]$ crontab -l
# user /bin/sh
SHELL=/bin/sh
# mail to oracle user
MAILTO=oracle
# run at 9:45 AM monday thur friday
45 09 * * 1-5 /home/oracle/scripts/tblspc_usage.sh 2>&1 /home/oracle/scripts/tblspc_usage.log

[oracle@dub-ImrORA3 scripts]$ ls -al tblspc_usage.sh
-rwxrwxr-- 1 oracle oinstall 2013 Jan 20 09:12 tblspc_usage.sh

いいですね。 /var/mail/oracle /home/oracle/scripts/tblspc_usage.sh から送信されるメールは次のとおりです。行15:sqlplus:コマンドが見つかりません。 grep:body.log: そのファイルまたはディレクトリはありません。

これは私のシェルスクリプトです。

#!/bin/sh
#
# tblspc_usage.sh
#=======================================
#
# Checks for tablespace usage exceeding 90% and email the details
# does not check undo or temp tablespaces
#=======================================
#
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ; export ORACLE_HOME
ORACLE_SID=IMR1 ; export ORACLE_SID
user="system"
pass="letmein" # bogus passwd

sqlplus -S $user/$pass <<EOF
   column "TOTAL ALLOC (MB)"      format 9,999,990.00
   column "TOTAL PHYS ALLOC (MB)" format 9,999,990.00
   column "USED (MB)"             format 9,999,990.00
   column "FREE (MB)"             format 9,999,990.00
   column "% USED"                format 990.00
   set echo off
   spool body.log
   select 
       a.tablespace_name,
       a.bytes_alloc/(1024*1024)               "TOTAL ALLOC (MB)",
       a.physical_bytes/(1024*1024)            "TOTAL PHYS ALLOC (MB)",
       nvl(b.tot_used,0)/(1024*1024)           "USED (MB)",
       (nvl(b.tot_used,0)/a.bytes_alloc)*100   "USED %"
   from 
       (select 
            tablespace_name,
            sum(bytes) physical_bytes,
            sum(decode(autoextensible,'NO',bytes,'YES',maxbytes)) bytes_alloc
        from 
            dba_data_files
        group by 
            tablespace_name ) a,
   (select 
        tablespace_name, 
        sum(bytes) tot_used
    from 
        dba_segments
    group by 
        tablespace_name ) b
  where 
        a.tablespace_name = b.tablespace_name (+)
  and 
        a.tablespace_name not in 
           (select distinct 
                   tablespace_name 
            from 
                   dba_temp_files
           )
  and      
        a.tablespace_name not like 'UNDO%'
  and
       ( nvl(b.tot_used,0)/a.bytes_alloc)*100 >= 90.00
  order by 1;

    spool off
    exit
EOF

   # if the word "TABLESPACE" exists in the spool file 
   # then at least one tablespace has usage over 90%
   if grep -q TABLESPACE "body.log";
   then
        cat /home/oracle/scripts/body.log | mailx -s "ORA3 - Tablespace(s) 90% Full" \
        [email protected]
   fi

ベストアンサー1

メッセージがsqlplus: command not found答えを与えた。環境変数ORACLE_HOMEを設定したので、ORACLE_HOMEをエクスポートしてスクリプトに次の行を入力します。

export PATH=$PATH:$ORACLE_HOME/bin

私もTNS_ADMINエクスポートについて迷信しています。

export TNS_ADMIN=$ORACLE_HOME/network/admin

これが必ず必要なのかはわかりません。

おすすめ記事