20120803 AIX_shell监控指定目录下是否有指定的文件名的文件生产

 

问题描述: EVC前台突然挂了,登陆不了,有一个目录下面不断的有dump文件和core文件产生,研发找不出原因,写了一个脚本监控,可以将文件按照指定的格式生成,发送到sdp上面,然后发短信告警,可以瞬间重启,减少被客户发现概率。

----号码,目录,文件名可以配置

 

autoFtp.sh
-------------------------------------------------------
smsbillName=$1

ftp -n << EOF
open IP
user 用户 密码
cd /tellin/tellinapp/scu/sms/iuserbill/smsbill
lcd /home/sysMonitor/smsbill
put $smsbillName
bye
EOF

 

monitor_fileName_create.sh   路径和文件名可配置
----------------------------------------------------
recievers="9779802034218"
serverName=`hostname|sed 's/[a-b]$//'`

homePath=/home/sysMonitor

if [ ! -d ${homePath}/smsbill ]; then
        mkdir -p ${homePath}/smsbill
fi
if [ ! -d ${homePath}/smsbill_bak ]; then
        mkdir -p ${homePath}/smsbill_bak
fi
if [ ! -f ${homePath}/currentSerial ]; then
        echo 0 > ${homePath}/currentSerial
fi
########################################################################
## Send SMS
########################################################################
function sendSMS
{
        currentDate=`date +%Y%m%d`
        smsDate=`date`
        smsContent="$smsContent Time:$smsDate"
        messageLenth=`expr length "$smsContent"`
        for reciever in `echo $recievers`
        do
                echo $reciever
                lastSerial=`cat $homePath/currentSerial`
                currentSerial=`expr $lastSerial + 1`
                echo $currentSerial > $homePath/currentSerial
                smsbillName=sm${currentDate}_101_${currentSerial}${serverName}.unl
                smsbillContent="1 0 $reciever `date +%Y/%m/%d` `date +%T` 1 1 $messageLenth $smsContent"
                echo $smsbillContent > ${homePath}/smsbill/${smsbillName}        
                ${homePath}/autoFtp.sh ${smsbillName}
               
               
                mv ${homePath}/smsbill/${smsbillName} ${homePath}/smsbill_bak/
               
        done
}
########################################################################
## 检查15分钟内指定目录下是否有指定的文件产生
########################################################################
filePaths="/home/evcweb/evc/jboss/bin|/home/evcweb/evc/jboss/bin"
fileNames="dump|javacore"
function checkFileContents
{
 
       nums=`echo $fileNames|awk -F "[|]" '{print NF}'`
       num=0
    while [ $num -ne nums ]
     do
      fileNum=0
      num=`expr $num + 1`
      filePath=`echo $filePaths|awk -F "[|]" -v num=$num '{print $num}'`
            fileName=`echo $fileNames|awk -F "[|]" -v num=$num '{print $num}'`
            fileNum=`ls -alrt ${filePath} | grep ${fileName} | wc -l`
      if [ fileNum -ne 0 ]; then
        smsContent="Alarm :There are ${fileNum} ${fileName} file created in ${serverName},please check if we can login EVC WEB or not"
        sendSMS
      fi
      done
}
checkFileContents

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值