#!/bin/sh # configurations # computer 設備名稱 # target 監控目標 # watcher 跟蹤者(郵箱) computer="ehetong" target="home/ehetong/apache-tomcat-7.0.33" date_time=$(date +%c) # 收件人 email_addressee="952589031@qq.com 823633682@qq.com" # 發件人 email_sender="do-not-reply@itrusign.cn" # 發件人用戶名 email_user="do-not-reply@itrusign.cn" # 發件人密碼 email_password="XXXXXXXXXXXXXXXXXXXXXXXXXXXX" # smtp服務器地址 email_smtp="smtp.exmail.qq.com" # 郵件標題 email_title=${computer}"機器TOMCAT進程意外關閉-"${date_time} # 郵件內容 email_content=${computer}"---"${target}"\n在"${date_time}",Tomcat進程意外關閉\\nshell腳本搜索不到Tomcat進程PID,請及時處理。" #tomcat=$(ps -ef|grep $$target | grep -v grep | awk '{print $2}') tomcat=`ps -ef|grep $target | grep -v 'grep\|tail' | awk '{print $2}'` #file_path="" # 附件 # file_path="" # -a ${file_path} if test -z ${tomcat} then echo $(date +%F" "%T)"--info--:准備發送郵件" /usr/local/bin/sendEmail -f ${email_sender} -t ${email_addressee} -s ${email_smtp} -u ${email_title} -xu ${email_user} -xp ${email_password} -m ${email_content} -o message-charset=utf-8 echo $(date +%F" "%T)"--info--:發送郵件成功" else echo $(date +%F" "%T)"--info--:tomcat進程存在,pid="${tomcat} fi