Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 7th, 2008, 10:07 AM
matchey matchey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 matchey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 32 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 7th, 2008, 11:25 AM
LKBrwn_DBA LKBrwn_DBA is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 294 LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 16 h 48 m 15 sec
Reputation Power: 9

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

__________________

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Vaildation in UNIX script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway