当一台服务器上有很多侦听时,如何用脚本一次起动
#!/usr/bin/sh ############################################# # # Start the tnslistener # ############################################# start_tnslstnr() { echo $(date) "Start TNSLISTENER $oraid" oraidlitener= cat $oraidlitener | grep -v "SID_LIST" |grep -v ")" grep -v "^#" $oraidlitener | while read line do echo $line | grep -q "(" if [ $? -eq 0 ] then echo $line break fi echo $line | grep -q "=" if [ $? -eq 0 ] then LISTENER=$(echo $line | cut -f 1 -d '=') echo "$oraid's listener name is $LISTENER" su - $oraid -c 'lsnrctl start $LISTENER & wait' >/dev/null 2>&1 0</dev/null su - $oraid -c 'lsnrctl status $LISTENER' 2>&1 0</dev/null RC=$? if [ $RC -eq 0 ] then echo $(date) "DONE : Start TNSLISTENER $oraid" echo $(date) "----------------------------------------------------------" else echo "-----------------------------------------------------------------" echo $(date) "WARNING: Start TNSLISTENER $oraid RC="$RC echo $(date) "##########################################################" listenererror=y echo "-----------------------------------------------------------------" fi echo "\n" echo "\n" fi done return 0 } ############################################# # # Main # ############################################# oraids=$(cat /etc/group|grep -i dba|cut -d ':' -f 4) oraids=$(echo $oraids |tr "," " ") for oraid in $oraids do echo "oracle $oraid is found and trying to found listener file"; oraidlitener=$(find / -name listener.ora|grep -v sample|grep -i $oraid); echo $oraid; echo $oraidlitener; start_tnslstnr; done