这篇文章主要介绍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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。