|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Vaildation in UNIX script
Hi,
I have a UNIX script which has two parts: 1. It connects to a database and refreshes a materialized view 2. It then connects to another database and inserts refresh statistics to a table The script works, but I'm not too good at UNIX validation. Currently, if the first part of the job fails - the entire script bombs out. What I would like it to do is, if the first part fails, then continue with the second part of the script, but still record an overall failure in the log file. Below is the code at present. I think I need some conditionsal 'flags' but do not know where to begin. Please can someone help? See below: . /usr/opt/oracle/cron/set_oraenv . ${SCRIPT_DIR}/set_connect_params export TOP_SCHEMA=${TOP_LOG} export WHSE_SCHEMA=${VIW_LOG} LOG_DIR=${SCRIPT_DIR}/logs SCHED_DATE=`date "+%y%m%d"` JOBSET_LOG=${LOG_DIR}/RUN_ROT_TOP_OCRS_MV_LOG_"$ENV"_$SCHED_DATE export JOBSET_LOG export LOG_DIR echo "`date`: Refresh of ROT_TOP_OCRS_MV started" >> ${JOBSET_LOG} ################################################################################# # # Run the refresh of the ROT_TOP_OCRS_MV materialized view and then gather stats. # Finally, insert an entry to COM_TABLE_LOAD_HIST to log the MV refresh. # ################################################################################# sqlplus -s ${TOP_LOG}/${TOP_PW}@${TOP_SID} <<END1>> ${JOBSET_LOG} whenever sqlerror exit 2 whenever oserror exit 3 set heading off set serveroutput on select 'User ID: '||user||CHR(13)||CHR(10)||'Connected to: '||rtrim(global_name,'.US.ORACLE.COM.ATOSORIGIN') from dual,global_name; select to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS') from dual; execute DBMS_OUTPUT.PUT_LINE('*** Now running the weekly ROT_TOP_OCRS_MV materialized view refresh ***'); execute DBMS_MVIEW.REFRESH('${TOP_SCHEMA}.ROT_TOP_OCRS_MV'); select to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS') from dual; execute DBMS_OUTPUT.PUT_LINE('*** Now gathering statistics ***'); exec DBMS_STATS.GATHER_TABLE_STATS(ownname => '${TOP_SCHEMA}',tabname => 'ROT_TOP_OCRS_MV',cascade => TRUE); select to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS') from dual; exit END1 if [ $? -ne 0 ] then echo "`date`: Refresh of ROT_TOP_OCRS_MV failed" >> ${JOBSET_LOG} exit 3 else echo "`date`: Refresh of ROT_TOP_OCRS_MV completed successfully" >> ${JOBSET_LOG} fi sqlplus -s ${VIW_LOG}/${VIW_PW} <<END1>> ${JOBSET_LOG} whenever sqlerror exit 2 whenever oserror exit 3 set heading off set serveroutput on select 'User ID: '||user||CHR(13)||CHR(10)||'Connected to: '||rtrim(global_name,'.US.ORACLE.COM.ATOSORIGIN') from dual,global_name; select to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS') from dual; execute DBMS_OUTPUT.PUT_LINE('*** Now inserting record stats to COM_TABLE_LOAD_HIST ***'); insert into COM_TABLE_LOAD_HIST select 'ROT_TOP_OCRS_MV',count(*),null,null,null,null,sysdate,'ROT_TOP_OCRS_MV last refreshed on '||to_char(sysdate,'DD-MON-RR') from ROT_TOP_OCRS_MV; commit; select to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS') from dual; exit END1 if [ $? -ne 0 ] then echo "`date`: Refresh of ROT_TOP_OCRS_MV failed" >> ${JOBSET_LOG} exit 3 else echo "`date`: Refresh of ROT_TOP_OCRS_MV completed successfully" >> ${JOBSET_LOG} exit 0 fi |
|
#2
|
|||
|
|||
|
Remove the exit 3 from both the following 'if' statements: Code:
if [ $? -ne 0 ]
then
echo "`date`: Refresh of ...etc.. failed" >> ${JOBSET_LOG}
#exit 3 <== comment out here
else
echo "`date`: Refresh of ...etc.. completed successfully" >> ${JOBSET_LOG}
fi
![]()
__________________
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Vaildation in UNIX script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|