Friday, November 11, 2005

You can never have too much redirection

And who needs PL/SQL anyway when you already have all the procedural control you need, thanks to Mr Stephen Bourne and his excellent Shell?

echo -------------------------------------  >> $LOGS/$MY_LOGFILE_NAME
echo Load the xxx schema tables for xyz >> $LOGS/$MY_LOGFILE_NAME
echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME
sqlplus -s $XXX_USERNAME/$XXX_PASSWORD @$XYZ_BIN/xyz_load_xxx_data.sql $LOGS $MY_ERRORFILE_NAME \
>> $LOGS/$MY_LOGFILE_NAME retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi echo ------------------------------------ >> $LOGS/$MY_LOGFILE_NAME echo Processing abc files >> $LOGS/$MY_LOGFILE_NAME echo ------------------------------------ >> $LOGS/$MY_LOGFILE_NAME $xyz_BIN/xyz_process_abc_ndt_files.pl retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi echo ------------------------------------ >> $LOGS/$MY_LOGFILE_NAME echo Processing MF files >> $LOGS/$MY_LOGFILE_NAME echo ------------------------------------ >> $LOGS/$MY_LOGFILE_NAME $xyz_BIN/xyz_process_def_ndt_files.pl retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME echo Merge MF and customer tables for xyz >> $LOGS/$MY_LOGFILE_NAME echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME sqlplus -s $XYZ_USERNAME/$XYZ_PASSWORD \
@$XYZ_BIN/xyz_merge_mf_and_customer_tables.sql $LOGS $MY_ERRORFILE_NAME \ >> $LOGS/$MY_LOGFILE_NAME retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME echo Populate equipment table for xyz >> $LOGS/$MY_LOGFILE_NAME echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME sqlplus -s $XYZ_USERNAME/$XYZ_PASSWORD \
@$XYZ_BIN/xyz_create_equipment.sql $LOGS $MY_ERRORFILE_NAME \
>> $LOGS/$MY_LOGFILE_NAME retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME echo Populate locations table for xyz >> $LOGS/$MY_LOGFILE_NAME echo ------------------------------------- >> $LOGS/$MY_LOGFILE_NAME sqlplus -s $XYZ_USERNAME/$XYZ_PASSWORD \
@$XYZ_BIN/xyz_create_locations.sql $LOGS $MY_ERRORFILE_NAME \
>> $LOGS/$MY_LOGFILE_NAME retcode=`echo \$?` if [ "$retcode" -ne 0 ] ;then echo Step failed >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_GENERIC_FAIL fi runendt=`date` echo ---------------------------------------------------- >> $LOGS/$MY_LOGFILE_NAME echo "xyz dataload Ended - $runendt ....." >> $LOGS/$MY_LOGFILE_NAME echo ---------------------------------------------------- >> $LOGS/$MY_LOGFILE_NAME echo >> $LOGS/$MY_LOGFILE_NAME exit $RETURN_SUCCESS

2 comments:

OraWTFGuy said...

Remind me where the echoes are going to...?

Actually, this stings a bit, because my ksh batch scripts from days of yore looked a lot like this. But at least I used a ksh function to encapsulate the status code checking ;o)

William Robertson said...

Would you have the heart to tell that guy he could have just used this once at the start:

exec > $LOGS/$MY_LOGFILE_NAME 2>&1

Or just leave it to the calling script.

Or not have a damn script.