talk is cheap,here is the code:
#!/bin/sh export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1/ export PATH=$PATH:$ORACLE_HOME/bin export base_path=/home/peteryrcc/code/database sqlplus account/'password'@10.75.65.142:1521/database name <<EOF spool /home/peteryrcc/code/database/current_dmtc.log @/home/peteryrcc/code/database/dmtc_monitoring.sql spool off EOF export current=$base_path/current_dmtc.log export historical=$base_path/historical_dmtc.log grep 'NEW' $current>/dev/null if [ $? -ne 0 ];then grep 'NEW' $historical>/dev/null if [ $? -ne 0 ];then echo 'no found all the time' else cat $current>$historical echo $(date)-------"no found !">>$base_path/dmtc_monitoring.log echo 'the DMTC status has been turn to completed, please perform the update'|mail -s "DOCTOR_MODEL_TYPE_CODE issue! " peteryang.rcc@cn.luxottica.com Amy.Xiong@cn.luxottica.com fi else grep 'NEW' $historical>/dev/null if [ $? -eq 0 ];then echo 'found all the time' else cat $current>$historical echo $(date)-------"found DMTC=11">>$base_path/dmtc_monitoring.log cat $current|grep -v SQL|mail -s "DOCTOR_MODEL_TYPE_CODE issue! " peteryang.rcc@cn.luxottica.com Amy.Xiong@cn.luxottica.com fi fi