SAP BASIS query oracle sdbah table for show backup log for send to mail.

** Myself
Unix Shell Script
#!/bin/sh
su - oraprd  << BOF
sqlplus "/ as sysdba" << EOF
set linesize 120
spool /tmp/backup_PRD.log
select 'PRD ' || SYSID || ',Backup to Disk,' || to_char(to_date(BEG,'YYYYMMDDHH24MISS'),'DD-MON-YYYY HH:MI:SS') || ',' ||
CASE
WHEN ENDE =' '  THEN 'Backup Not Completed'
ELSE
to_char(to_date(ENDE,'YYYYMMDDHH24MISS'),'DD-MON-YYYY HH:MI:SS')
END
|| ',' || RC "SID,Backup Type,Begin,End,RC "
from sapPRD.sdbah "Backup Logs"  where BEG >  to_char(sysdate-6,'YYYYMMDD') and funct = 'afd' order by  BEG desc;
spool off
EOF
BOF
cat /tmp/backup_PRD.log |egrep -v "SQL|CASE|WHEN|CASE|END|ELSE|Logs|'" > /tmp/backup_PRD_all.log
mailx -s "Backup Log IDES (PRD)" -r PRDadmin@abc.com  SAPadmin@abc.com < /tmp/backup_PRD_all.log
 
Window Bat Script
set ORACLE_SID=PRD
set CONNECT_BAT=D:\script\connect.bat
set EXECUTE_BAT=D:\script\command.bat
set EXECUTE_TEMP=D:\script\command.txt
set SPOOL_LOG=D:\script\BACKUP_PRD.txt
echo ------------------------------------------------  >> ^%SPOOL_LOG%
date /T  >  ^%SPOOL_LOG%
echo ------------------------------------------------  >> ^%SPOOL_LOG%
echo sqlplus /nolog > ^%CONNECT_BAT%
echo connect /@PRD as sysdba > ^%EXECUTE_BAT%
echo set linesize 120 >> ^%EXECUTE_BAT%
echo select 'PRD_Backup_to_Disk,' ^|^| to_char(to_date(BEG,'YYYYMMDDHH24MISS'),'DD-MON-YYYY HH:MI:SS') ^|^| ',' ^|^|  >> ^%EXECUTE_BAT%
echo CASE >> ^%EXECUTE_BAT%
echo  WHEN ENDE =' '  THEN 'Backup Not Completed' >> ^%EXECUTE_BAT%
echo  ELSE to_char(to_date(ENDE,'YYYYMMDDHH24MISS'),'DD-MON-YYYY HH:MI:SS') >> ^%EXECUTE_BAT%
echo END >> ^%EXECUTE_BAT%
echo ^|^| ',' ^|^| RC "SID,Backup_Type,Begin,End,RC " from sapr3.sdbah "Backup_Logs" where BEG ^>  to_char(sysdate-6,'YYYYMMDD') and FUNCT = 'afd' order by  BEG desc; >> ^%EXECUTE_BAT%
call ^%CONNECT_BAT% < ^%EXECUTE_BAT%  >> ^%SPOOL_LOG%
echo ------------------------------------------------  >> ^%SPOOL_LOG%
del ^%CONNECT_BAT%
del ^%EXECUTE_BAT%
del ^%EXECUTE_TEMP%

0 comments:

Loading