Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1824996
  • 博文数量: 276
  • 博客积分: 1574
  • 博客等级: 上尉
  • 技术积分: 2894
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-26 23:23
个人简介

生活的美妙在于,不知道一下秒是惊艳还是伤神,时光流转,珍惜现在的拥有的时光

文章分类

全部博文(276)

文章存档

2017年(17)

2016年(131)

2015年(63)

2013年(2)

2012年(32)

2011年(31)

分类: Python/Ruby

2012-05-14 17:48:24


点击(此处)折叠或打开

  1. #! /bin/bash
  2. 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
  3. DATETIME=`date +%F`
  4. serpath=/app/service/ser/bin
  5. serlog=/app/service/serrestart.log
  6. serdate=`date +%F.%T`
  7. serip=`/sbin/ifconfig |grep 'inet addr'|grep 192 |awk -F: '{print $2}'|awk '{print $1}'`
  8. seruser=`whoami`
  9. #####mailsend
  10. mailtitle="ser information $serdate $serip "
  11. mailmessagefile=$HOME/mail.txt #邮件信息内容
  12. mailmessage= #邮件信息内容
  13. #mailcatcher=noc@test.com
  14. mailcatcher=talen.hao@test.com #邮件接收者
  15. mailsender=ser@test.com #邮件发送者
  16. serPIDFILE=/app/service/ser/user-attributes-database.pid


  17. #####
  18. statusser()
  19. {
  20.         ps -ef |grep ser |grep java|grep -v grep |awk '{print $2}'
  21. }
  22. Uadrestart()
  23. {
  24.         cd $serpath
  25.         echo ">>>>> $serdate : 当前目录 `pwd`"
  26.         pidold=`statusser`
  27.         echo ">>>>> $serdate : Old PID NO. is <$pidold>"
  28.         #./misctrl.sh stop
  29.         kill -9 $pidold
  30.         rm -v $serPIDFILE
  31.         sleep 1
  32.         ./misctrl.sh start
  33.         pidnew=`statusser`
  34.         echo ">>>>> $serdate : New PID NO. is <$pidnew>"
  35. }

  36. Status(){
  37.         if [ -f $serPIDFILE ]
  38.         then
  39.                 if test -z $pidnew -o $pidnew = $pidold
  40.                 then
  41.                         mailmessage='ser service restarted failure'
  42.                         echo "$serdate : $serip $mailmessage" > $mailmessagefile
  43.                         echo "$serdate : Old PID NO. is <$pidold>" >> $mailmessagefile
  44.                         echo "$serdate : New PID NO. is <$pidnew>" >> $mailmessagefile
  45.                         echo "$serdate : restarted faild ==> $mailmessage"
  46.                         isok=failure
  47.                 else
  48.                         mailmessage='ser service restarted success'
  49.                         echo "$serdate : $serip $mailmessage" > $mailmessagefile
  50.                         echo "$serdate : Old PID NO. is <$pidold>" >> $mailmessagefile
  51.                         echo "$serdate : New PID NO. is <$pidnew>" >> $mailmessagefile
  52.                         echo "$serdate : restarted ok ==> $mailmessage"
  53.                         isok=success
  54. fi
  55.         else
  56.                 mailmessage='ser service restarted failure'
  57.                 echo "$serdate : $serip $mailmessage" > $mailmessagefile
  58.                 echo "$serdate : Old PID NO. is <$pidold>" >> $mailmessagefile
  59.                 echo "$serdate : New PID NO. is <$pidnew>" >> $mailmessagefile
  60.                 echo "$serdate : restarted faild ==> $mailmessage"
  61.                 isok=failure
  62.                 exit 1
  63. fi
  64. }

  65. MailSend()
  66. {
  67.         `which mail` -v -s "$mailtitle $isok" $mailcatcher -- -f $mailsender < $mailmessagefile
  68. }

  69. vim.mailrc()
  70. {
  71.         cp -v $HOME/.mailrc{,.bak$DATETIME-`echo $RANDOM`}
  72.         echo 'set from=sender@126.com smtp=smtp.126.com' > $HOME/.mailrc
  73.         echo 'set smtp-auth-user=sender@126.com smtp-auth-password=sender.com' >> $HOME/.mailrc
  74.         echo 'set smtp-auth=login' >> $HOME/.mailrc
  75. }
  76. MAIL()
  77. {
  78.         if test -f $HOME/.mailrc
  79.         then
  80.                 MailSend
  81.         else
  82.                 echo ".mailrc文件不存在,将创建此文件"
  83.                 vim.mailrc
  84.                 MailSend
  85.         fi
  86. }
  87. if [ $seruser == service ]
  88. then
  89.         echo ">>>>>$serdate : 开始执行重起服务"
  90.         Uadrestart
  91.         Status
  92.         MAIL
  93.         exit 0
  94. else
  95.         echo ">>>>>$serdate : 严重!!使用service 用户运行此脚本"
  96.         exit 1
  97. fi

阅读(2964) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~