您的位置:首页 > 大数据 > 人工智能

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

2012-08-03 00:02 483 查看
 

问题描述: 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

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐