![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| validation on a parameter | Henley55 | UNIX for Dummies Questions & Answers | 1 | 04-20-2008 04:33 PM |
| How Can I Do Time Validation in UNIX | mosammey | UNIX for Dummies Questions & Answers | 4 | 11-26-2007 12:02 PM |
| Time Validation in UNIX? | mosammey | Shell Programming and Scripting | 1 | 11-21-2007 02:23 PM |
| Need help in file validation by shell script | srichakra | Shell Programming and Scripting | 1 | 07-19-2007 02:22 PM |
| Filename Validation | F-1 | UNIX for Advanced & Expert Users | 2 | 05-02-2006 01:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
UNIX script Validation
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 |
|
||||
|
Code:
. /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}
status=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 || $status -eq 3 ]]
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|