linux自動重起服務,併傳送郵件通知結果
點選(此處)摺疊或開啟
-
#! /bin/bash
- PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/service/bin:/app/service/bin:/usr/local/java/jdk1.6.0_20/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/service/bin
- DATETIME=`date +%F`
- serpath=/app/service/ser/bin
- serlog=/app/service/serrestart.log
- serdate=`date +%F.%T`
- serip=`/sbin/ifconfig |grep `inet addr`|grep 192 |awk –F: `{print $2}`|awk `{print $1}``
- seruser=`whoami`
- #####mailsend
- mailtitle=“ser information $serdate $serip “
- mailmessagefile=$HOME/mail.txt #郵件資訊內容
- mailmessage= #郵件資訊內容
- #mailcatcher=noc@test.com
- mailcatcher=talen.hao@test.com #郵件接收者
- mailsender=ser@test.com #郵件傳送者
- serPIDFILE=/app/service/ser/user–attributes–database.pid
- #####
- statusser()
- {
- ps –ef |grep ser |grep java|grep –v grep |awk `{print $2}`
- }
- Uadrestart()
- {
- cd $serpath
- echo “>>>>> $serdate : 當前目錄 `pwd`”
- pidold=`statusser`
- echo “>>>>> $serdate : Old PID NO. is “
- #./misctrl.sh stop
- kill –9 $pidold
- rm –v $serPIDFILE
- sleep 1
- ./misctrl.sh start
- pidnew=`statusser`
- echo “>>>>> $serdate : New PID NO. is “
- }
- Status(){
- if [ –f $serPIDFILE ]
- then
- if test –z $pidnew –o $pidnew = $pidold
- then
- mailmessage=`ser service restarted failure`
- echo “$serdate : $serip $mailmessage” > $mailmessagefile
- echo “$serdate : Old PID NO. is “ >> $mailmessagefile
- echo “$serdate : New PID NO. is “ >> $mailmessagefile
- echo “$serdate : restarted faild ==> $mailmessage”
- isok=failure
- else
- mailmessage=`ser service restarted success`
- echo “$serdate : $serip $mailmessage” > $mailmessagefile
- echo “$serdate : Old PID NO. is “ >> $mailmessagefile
- echo “$serdate : New PID NO. is “ >> $mailmessagefile
- echo “$serdate : restarted ok ==> $mailmessage”
- isok=success
- fi
- else
- mailmessage=`ser service restarted failure`
- echo “$serdate : $serip $mailmessage” > $mailmessagefile
- echo “$serdate : Old PID NO. is “ >> $mailmessagefile
- echo “$serdate : New PID NO. is “ >> $mailmessagefile
- echo “$serdate : restarted faild ==> $mailmessage”
- isok=failure
- exit 1
- fi
- }
- MailSend()
- {
-
`which mail` –v –s “$mailtitle $isok” $mailcatcher –– –f $mailsender $mailmessagefile
- }
- vim.mailrc()
- {
- cp –v $HOME/.mailrc{,.bak$DATETIME–`echo $RANDOM`}
- echo `set from=sender@126.com smtp=smtp.126.com` > $HOME/.mailrc
- echo `set smtp-auth-user=sender@126.com smtp-auth-password=sender.com` >> $HOME/.mailrc
- echo `set smtp-auth=login` >> $HOME/.mailrc
- }
- MAIL()
- {
- if test –f $HOME/.mailrc
- then
- MailSend
- else
- echo “.mailrc檔案不存在,將建立此檔案”
- vim.mailrc
- MailSend
- fi
- }
- if [ $seruser == service ]
- then
- echo “>>>>>$serdate : 開始執行重起服務”
- Uadrestart
- Status
- exit 0
- else
- echo “>>>>>$serdate : 嚴重!!使用service 使用者執行此指令碼”
- exit 1
- fi
相關文章
- linux下設定郵件自動傳送Linux
- Python3實現自動傳送MySql查詢併傳送郵件PythonMySql
- Springboot 自動傳送郵件Spring Boot
- 【Grafana】告警配置併傳送郵件Grafana
- rman備份指令碼 傳送郵件通知指令碼
- Linux 上使用 Gmail SMTP 伺服器傳送郵件通知LinuxAI伺服器
- 自動監控Oracle 表空間資訊併傳送郵件指令碼Oracle指令碼
- [linux]linux傳送郵件Linux
- Linux自動下傳送HTML格式並帶附件的郵件LinuxHTML
- python實現自動監控網站併傳送郵件告警薦Python網站
- 郵件傳送
- 傳送郵件
- 使用Linux命令傳送郵件Linux
- linux formail 傳送html郵件LinuxORMAIHTML
- 如何在 Linux 上使用 Gmail SMTP 伺服器傳送郵件通知LinuxAI伺服器
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- ASP.NET自動傳送郵件功能的實現ASP.NET
- 自動生成addm報告並以郵件傳送
- 自動生成AWR報告並以郵件附件傳送
- Laravel 傳送郵件Laravel
- PHP傳送郵件PHP
- Django——郵件傳送Django
- java郵件傳送Java
- Laravel傳送郵件Laravel
- gmail傳送郵件AI
- Oracle郵件傳送Oracle
- java傳送郵件Java
- Powershell郵件傳送
- thinkphp 郵件傳送PHP
- centos 傳送郵件CentOS
- phpcms傳送郵件PHP
- 郵件的傳送
- Linux 如何啟動mail郵件服務LinuxAI
- JAVA 資料寫入excel併傳送郵件JavaExcel
- 郵件營銷自動化:批次郵箱API傳送技巧與策略API
- 高可用服務之Keepalived郵件通知配置
- Linux配置msmtp+mutt傳送郵件(可放在指令碼中定時傳送郵件)Linux指令碼
- Redmine釋出新聞,自動傳送郵件功能失效恢復