Oracle Linux 5.10
Eu posso executar manualmente o script "tblspc_usage.sh" com sucesso como o usuário oracle. Eu sei disso porque me envia um relatório por e-mail.
Mas não é executado a partir do cron. Não gera um arquivo de log.
[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
Ok, aqui está o email em / var / mail / oracle
/home/oracle/scripts/tblspc_usage.sh: linha 15: sqlplus: comando não encontrado
grep: body.log: Nenhum arquivo ou diretório desse tipo
Aqui está o meu script de shell:
#!/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