您好,登錄后才能下訂單哦!
這篇文章主要介紹SharePlex如何基于Solaris 10 Linux實現自動巡檢腳本,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
1.check腳本,可單獨執行,也可通過start腳本調用
#!/bin/bash # Created by czh version v1.0 # This script was used to check SharePlex Instance health. # This Script was created on RHEL 7.6 Platform and SunsOS 10.5. ############################################################################################################################################ #MailUserName='yourname@yourcompany' #if [ "$MailUserName" = "yourname@yourcompany" ] # then # echo "Please modify the script so it has a valid email address" # exit 0 #fi ############################################################################################################################################ # Start Scripts v_cop=`ps -ef|grep sp_cop|grep -v grep|awk '{print $2}'` v_num_cop=`ps -ef|grep sp_cop|grep -v grep|awk '{print $2}'|wc -l` v_os=`uname -a|awk '{print $1}'` i=1 if [ ${v_os} = "SunOS" ];then while [ $i -le ${v_num_cop} ] do v_pid=`echo ${v_cop}|/usr/xpg4/bin/awk -v v_i="${i}" '{print $v_i}'` v_script_name=`echo $0` v_dirname=`dirname ${v_script_name}` SP_SYS_HOST_NAME=`pfiles ${v_pid}|grep sockname|sed -n '$p'|awk '{print $3}'` SP_PORT=`pfiles $v_pid|grep sockname|sed -n '$p'|awk '{print $5}'` SP_PRODIR=`ps -ef|grep sp_cop|grep -v grep|grep ${v_pid}|awk '{print $8}'|cut -d '.' -f1|sed 's/\/$//'` SP_SYS_VARDIR=`pfiles ${v_pid}|sed -n '$p'|sed -n 's/\/rim//p'|tr -d " "` export SP_SYS_VARDIR export SP_SYS_HOST_NAME ${SP_PRODIR}/bin/sp_ctrl > ${v_dirname}/splex_temp.log <<EOF show version full exit EOF v_sp_version=`cat ${v_dirname}/splex_temp.log|grep -i "Version"` v_err_count=`egrep -i '(^Stopping|Aborting|Idle|Stopped by user|error)' ${v_dirname}/splex_temp.log |wc -l` if [ ${v_err_count} -eq 0 ];then echo -e "\n*********************************************" echo -e "`date +%A' '%F' '%H:%M:%S`" echo -e " SharePlex All Process Was Running " echo -e "*********************************************" else echo -e "\n*********************************************" echo -e " !!! Warnings !!!" echo -e " SharePlex Process Has Problems,Please Check!" echo -e "SharePlex Warnings ${SP_SYS_HOST_NAME}:${SP_PORT} Has Problems." #|mail -s 'SharePlex Warnings!' ${MailUserName} echo -e " `date +%A' '%F' '%H:%M:%S` " echo -e "*********************************************" fi echo -e "\n****************************************************************************************" echo -e " SharePlex Instance ${SP_PORT} Bind IP Address Is : ${SP_SYS_HOST_NAME}:${SP_PORT}" echo -e " SharePlex Product Directory Is : ${SP_PRODIR}" echo -e " SharePlex Version Is : ${v_sp_version}" echo -e " SharePlex Instance Vardir Directory Is : ${SP_SYS_VARDIR}" echo -e " SharePlex Instance Cop Process Identifier Is : ${v_pid}" echo -e " `date +%A' '%F' '%H:%M:%S`" echo -e "****************************************************************************************\n" i=$(($i+1)) done rm -f ${v_dirname}/splex_temp.log echo -e "\n######################################################################################################################" echo -e "\nFinished check SharePlex instance!" echo -e "`date +%A' '%F' '%H:%M:%S`\n" echo -e "######################################################################################################################\n" elif [ ${v_os} = "Linux" ];then while [ $i -le ${v_num_cop} ] do v_pid=`echo ${v_cop}|awk -v v_i="${i}" '{print $v_i}'` v_script_name=`echo $0` v_dirname=`dirname ${v_script_name}` v_sp_ipaddr=`netstat -anp|grep tcp|grep ${v_pid}|awk '{print $4}'` SP_SYS_HOST_NAME=`echo ${v_sp_ipaddr%:*}` SP_PORT=`echo ${v_sp_ipaddr##*:}` SP_PRODIR=`ps -ef|grep sp_cop|grep -v grep|grep ${v_pid}|awk '{print $8}'|cut -d '.' -f1|sed 's/\/$//'` SP_SYS_VARDIR=`ls -l /proc/${v_pid}/cwd|awk '{print $11}'|sed -n 's/\/dump$//p'` export SP_SYS_VARDIR export SP_SYS_HOST_NAME ${SP_PRODIR}/bin/sp_ctrl > ${v_dirname}/splex_temp.log <<EOF show version full exit EOF v_sp_version=`cat ${v_dirname}/splex_temp.log|grep -i "Version"` v_err_count=`egrep -i '(^Stopping|Aborting|Idle|Stopped by user|error)' ${v_dirname}/splex_temp.log |wc -l` if [ ${v_err_count} -eq 0 ];then echo -e "\n*********************************************" echo -e "`date +%A' '%F' '%H:%M:%S`" echo -e " SharePlex All Process Was Running " echo -e "*********************************************" else echo -e "\n*********************************************" echo -e " !!! Warnings !!!" echo -e " SharePlex Process Has Problems,Please Check!" echo -e "SharePlex Warnings ${SP_SYS_HOST_NAME}:${SP_PORT} Has Problems." echo -e " `date +%A' '%F' '%H:%M:%S` " echo -e "*********************************************" fi echo -e "\n****************************************************************************************" echo -e " SharePlex Instance ${SP_PORT} Bind IP Address Is : ${SP_SYS_HOST_NAME}:${SP_PORT}" echo -e " SharePlex Product Directory Is : ${SP_PRODIR}" echo -e " SharePlex Version Is : ${v_sp_version}" echo -e " SharePlex Instance Vardir Directory Is : ${SP_SYS_VARDIR}" echo -e " SharePlex Instance Cop Process Identifier Is : ${v_pid}" echo -e " `date +%A' '%F' '%H:%M:%S`" echo -e "****************************************************************************************\n" i=$(($i+1)) done rm -f ${v_dirname}/splex_temp.log echo -e "\n######################################################################################################################" echo -e "\nFinished check SharePlex instance!" echo -e "`date +%A' '%F' '%H:%M:%S`\n" echo -e "######################################################################################################################\n" else echo "Caution : This Platform Are Not Support,Please Contact The Vendor." fi # End Scripts
2.Start腳本,不可單獨執行,需要調用上面check腳本
#!/bin/bash # Created by czh version v1.0 # This script was used to check SharePlex Instance health. # This Script was created on RHEL 7.6 Platform. v_log_dir_name=splex_check_log v_num_cop=`ps -ef|grep sp_cop|grep -v grep|awk '{print $2}'|wc -l` # 統計sp_cop數量 if [ ${v_num_cop} -le 0 ];then # 判斷是否存在sp_cop進程,如果不存在,提示并退出執行 echo -e "\n**************************************************************" echo -e " !!!No SharePlex Instance,Please Check!!! " echo -e "Please Check SharePlex Instance,The Sp_cop Process Not Active!" echo -e "**************************************************************\n" else echo -e "\n######################################################################################################################" echo -e "\nStarting Check" echo -e "`date +%A' '%F' '%H:%M:%S`\n" echo -e "######################################################################################################################\n" while true do v_dirname=`dirname $0` # 通過特殊變量$0取腳本名稱,使用dirname取路徑,確保下面創建文件在腳本所在路徑 if [ -d "${v_dirname}/${v_log_dir_name}" ];then echo "Notice: splex_check_log directory already exist,will continue." else mkdir -p ${v_dirname}/${v_log_dir_name} fi interval=1200 log_name=shareplex_check v_date=`date +%A-%F-%H%M%S` ${v_dirname}/check_shareplex_health.sh >> ${v_dirname}/${v_log_dir_name}/${log_name}_${v_date}.log & # 調用check_shareplex_health.sh腳本完成檢查 v_dir_size=`du -sk "${v_dirname}/${v_log_dir_name}"/|awk '{print $1}'` echo ${v_file_size} if [ ${v_dir_size} -ge 51200 ];then rm -rf ${v_dirname}/${v_log_dir_name} fi sleep ${interval} done fi
3.Stop腳本
#!/bin/bash # Created by czh version v1.0 # This script was used to check SharePlex Instance health. # This Script was created on RHEL 7.6 Platform. kill -9 `ps -ef|grep check_shareplex_health.sh|grep -v grep|awk '{print $2}'` 2>/dev/null kill -9 `ps -ef|grep start_check.sh|grep -v grep|awk '{print $2}'` 2>/dev/null
4.Readme文件
1.開始檢測 腳本作用: (1)會在腳本所在目錄創建splex_check_log目錄 (2)用于存放生成的SharePlex_Report_開頭的log文件,記錄SharePlex實例情況 (3)默認間隔20分鐘執行一次,可通過修改腳本interval參數更改執行頻率 (4)會自動刪除三天前或者當日志目錄超過50M會自動刪除目錄重建 (5)該腳本自動調用目錄下check_shareplex_health.sh腳本 (6)腳本執行步驟如下 chmod u+x start_check.sh chmod u+x stop_check.sh chmod u+x check_shareplex_health.sh ./start_check.sh & 2.停止腳本使用如下腳本 腳本作用: (1)找出執行腳本進程并執行kill命令 ./stop_check.sh 3.check_shareplex_health.sh腳本說明 (1)該腳本為start_check.sh腳本最終調用巡檢腳本 (2)郵箱發送告警功能默認為注釋狀態,如果告警發送郵件,則可以編輯check_shareplex_health.sh腳本 a.配置服務器sendmail功能,確保服務器可以發送郵件 b.去掉check_shareplex_health.sh開頭郵件部分注釋 c.修改MailUserName變量為需要發送郵件地址,并將48行管道符前面注釋#去掉,就可以使用郵件功能
以上是“SharePlex如何基于Solaris 10 Linux實現自動巡檢腳本”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。