TA的每日心情 | 开心 2023-8-9 11:05 |
---|
|
楼主 |
发表于 2023-12-20 17:40:13
|
显示全部楼层
- #!/bin/sh
- #usage:view listener status/config;sqlnet.ora;du size and analyze connect count by hour/minute/second to diag connection storm.
- #yu.c.zhang@oracle.com 20231219
- #modification:add by ip/program/user. 20240113
- #modification:add by program+host+user+ip;no_timed item sort by count desc. 20240115
- #define select prompt
- PS3="please select a num from menu:"
- #define logo
- function csslogo {
- echo -e "\033[31m*************************************************************************************************************************\033[0m"
- echo
- echo -e " \033[31m ${bold}ORACLE CSS DATABASE TOOLBOX\033[0m"
- echo -e
- echo -e "\033[31m b\033[0m: back to above menu"
- echo -e "\033[31m q\033[0m: exit the program"
- echo -e "\033[31m*************************************************************************************************************************\033[0m"
- }
- #define function to get lsnr
- function get_lsnr () {
- LSNR_COUNT=$(ps -ef|grep "/bin/tnslsnr"|grep -v grep|wc -l)
- if [ $LSNR_COUNT -eq 0 ]
- then
- echo No LISTENER Running !
- exit
- fi
- if [ $LSNR_COUNT -gt 0 ]
- then
- clear
- csslogo
- echo
- echo "Select the listener you want to operate: [Enter the Number]"
- echo "----------------------------------------------------------"
- select listeners in $( ps -ef | grep "/bin/tnslsnr"| grep -v grep | awk -v OFS=':' '{print $1,$8,$9}' )
- do
- integ='^[1-9]+$'
- if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${LSNR_COUNT} ];then
- echo "Error: Not a valid number!"
- else
- lsnr_owner=`echo ${listeners}|awk -v FS=':' '{print $1}'`
- lsnr_name=`echo $listeners|awk -v FS=':' '{print $3}'|tr "[:upper:]" "[:lower:]"`
- tnslsnr=`echo $listeners|awk -v FS=':' '{print $2}'`
- lsnr_path=`dirname $tnslsnr`
- lsnr_home=`dirname $lsnr_path`
- lsnr_logdir=`$lsnr_home/bin/lsnrctl <<EOF | grep log_directory | awk '{print $6}'
- set current_listener $lsnr_name
- show log_directory
- EOF`
- lsnr_trcfile=`$lsnr_home/bin/lsnrctl<<EOF | grep trc_directory | awk '{print $6"/"$1".log"}'
- set current_listener $lsnr_name
- show trc_directory
- EOF`
- if [ $USER != $lsnr_owner ];then
- echo "Please execute as LISTENER ownr:${lsnr_owner} !"
- exit
- fi
- break
- fi
- done
- fi
- }
- #define function to view config and status
- menul_view () {
- while true; do
- clear
- csslogo
- echo -e "====ORACLE-TOOLBOX-listener-analyze==="
- echo -e "\t1.vies status"
- echo -e "\t2.vies service"
- echo -e "\t3.view listener.ora"
- echo -e "\t4.view sqlnet.ora"
- echo -e "\t5.view file size"
- echo "================"
- read -p $'\e\033[33;5m$please enter option:\e\033[0m' choice
- case $choice in
- 1)
- echo
- echo -e "\t\033[31mlisnrctl status\033[0m"
- echo "-------------------------------------------"
- $lsnr_path/lsnrctl status $v_lsnr_name
- read -p "execute succesfully,enter any to continue..."
- ;;
- 2)
- echo
- echo -e "\t\033[31mlisnrctl service\033[0m"
- echo "-------------------------------------------"
- $lsnr_path/lsnrctl service $v_lsnr_name
- read -p "execute succesfully,enter any to continue..."
- ;;
- 3)
- echo
- echo -e "\t\033[31mlistener.ora\033[0m"
- echo "-------------------------------------------"
- cat `$lsnr_path/lsnrctl status $lsnr_name|grep "Parameter File"|awk '{print $4}'`
- read -p "execute succesfully,enter any to continue..."
- ;;
- 4)
- echo
- echo -e "\t\033[31msqlnet.ora\033[0m"
- echo "-------------------------------------------"
- cat $lsnr_home/network/admin/sqlnet.ora
- read -p "execute succesfully,enter any to continue..."
- ;;
- 5)
- echo
- echo -e "\t\033[31mLOG DIR USED in MB\033[0m"
- echo "-------------------------------------------"
- du -sm $lsnr_logdir
- echo
- echo -e "\t\033[31mTRACE FILE USED in MB\033[0m"
- echo "-------------------------------------------"
- du -sm $lsnr_trcfile
- read -p "execute succesfully,enter any to continue..."
- ;;
- b)
- menul;;
- q)
- exit;;
- *)
- echo "invalid option!"
- sleep 1;;
- esac
- done
- }
- #define function to analyze connect count
- menul_analyze () {
- while true; do
- clear
- csslogo
- echo -e "====ORACLE-TOOLBOX-listener-analyze==="
- echo -e "\t1.analyze by hour"
- echo -e "\t2.analyze by minite"
- echo -e "\t3.analyze by second"
- echo -e "\t4.analyze by ip "
- echo -e "\t5.analyze by program"
- echo -e "\t6.analyze by user"
- echo -e "\t7.analyze by program+host+user+ip"
- echo -e "\t8.analyze by specified ip and second"
- echo "================"
- read -p $'\e\033[33;5m$please enter option::\e\033[0m' choice
- case $choice in
- 1)
- echo -e "please type time like [$(date '+%d-%b-%Y'| tr '[:lower:]' '[:upper:]')]"
- read -p 'enter your time:' v_date
- echo
- echo " count by hour"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile | fgrep "establish" | awk '{print $1 " " $2}' | awk -F: '{print $1 }' | sort | uniq -c | sort -k 3
- read -p "execute succesfully,enter any to continue..."
- ;;
- 2)
- echo -e "please type time like [$(date '+%d-%b-%Y %H'| tr '[:lower:]' '[:upper:]')]"
- read -p 'enter your time:' v_date
- echo
- echo " count by minute"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile |fgrep "establish" |awk '{print $1 " " $2}' |awk -F: '{print $1 ":" $2 }' |sort |uniq -c|sort -k 3
- read -p "execute succesfully,enter any to continue..."
- ;;
- 3)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')]"
- read -p 'enter your time:' v_date
- echo
- echo " count by second"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile |fgrep "establish" |awk '{print $1 " " $2}' |awk -F: '{print $1 ":" $2 ":" $3 }' |sort |uniq -c|sort -k 3
- read -p "execute succesfully,enter any to continue..."
- ;;
- 4)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')] and cut until day/hour/minute"
- read -p 'enter your time:' v_date
- echo
- echo " count ip_address"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile|fgrep "establish"|grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | sort | uniq -c|sort -k1,1nr
- echo
- read -p "execute succesfully,enter any to continue..."
- ;;
- 5)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')] and cut until day/hour/minute"
- read -p 'enter your time:' v_date
- echo
- echo " count program"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile|fgrep "establish"|grep -oE "PROGRAM=[^)]+" | sort | uniq -c|sort -k1,1nr
- echo
- read -p "execute succesfully,enter any to continue..."
- ;;
- 6)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')] and cut until day/hour/minute"
- read -p 'enter your time:' v_date
- echo
- echo " count user"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile|fgrep "establish"|grep -oE "USER=[^)]+" | sort | uniq -c|sort -k1,1nr
- echo
- read -p "execute succesfully,enter any to continue..."
- ;;
- 7)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')] and cut until day/hour/minute"
- read -p 'enter your time:' v_date
- echo
- echo " count program+host+user+ip"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile|fgrep "establish"|grep -oP "PROGRAM=(\S+)\)\(HOST=(\S+)\)\(USER=(\S+).*?HOST=([\d\.]+)"|sort|uniq -c|sort -k1,1nr
- echo
- read -p "execute succesfully,enter any to continue..."
- ;;
- 8)
- echo -e "please type time like [$(date '+%d-%b-%Y %H:%M'| tr '[:lower:]' '[:upper:]')] and cut until day/hour/minute"
- read -p 'enter your time:' v_date
- read -p 'enter your ip_address:' v_address
- echo
- echo " count time"
- echo "--------- ----------------------------------------------------------"
- fgrep "$v_date" $lsnr_trcfile|fgrep "establish"|fgrep $v_address|awk -F* '{print $1 " " $3}'|awk -F= '{ print $1 " " $4}'|sed -e 's/......$//g'| awk '{print $1 " " $2 " " $4}'|sort |uniq -c
- read -p "execute succesfully,enter any to continue..."
- ;;
- b)
- menul;;
- q)
- exit;;
- *)
- echo "invalid option!"
- sleep 1;;
- esac
- done
- }
- #define main program
- function menul() {
- while true; do
- clear
- csslogo
- echo -e "====ORACLE-TOOLBOX-listener==="
- echo -e "\t1.status and config file"
- echo -e "\t2.analyze conn rate"
- echo -e "================"
- read -p $'\e\033[33;5m$please enter option::\e\033[0m' choice
- case $choice in
- 1)
- get_lsnr
- menul_view
- read -p "execute succesfully,enter any to continue..."
- ;;
- 2)
- get_lsnr
- menul_analyze
- read -p "execute succesfully,enter any to continue..."
- ;;
- b)
- menua
- ;;
- q)
- exit
- ;;
- *)
- echo "invalid option!"
- sleep 1
- ;;
- esac
- done
- }
- #execute main program
- menul
复制代码
|
|