web analytics

Redirect script output to the log

If the whole output of the complex script should be redirected to the log, the following trick could be used.

if [ "$1" != "-log" ] ; then                                      $0 -log "$@" 2>&1 | tee the_log_file.$$.log                  
   echo "The log file for the current session: the_log_file.$$.log"  
   exit 0                                                      
fi                                                            
shift  # remove "-log" parameter

Search for Oracle errors in the alert log

Search for Oracle errors in the last $NUM lines.

NUM=1000 SIGNAL_LIST=’^(…-|Error|Starting.*instance)|terminating instance’ tail -$NUM alert_${ORACLE_SID}.log | awk ‘ BEGIN {prev="" ; ret=1 } /’"$SIGNAL_LIST"’/ { if ( prev !~ /’"$SIGNAL_LIST"’/ ) { print "" ; print prev;} print $0;ret=0} {prev=$0} END { exit ret } ‘

On Unix Oracle alert log is normally located in […]