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
相关文章推荐
- 用shell监控站点目录下的文件是否被修改
- 当url中未明确指定文件名时,是否列出相关目录下所有文件的开关设置
- LinuxShell-检查指定目录是否存在shell脚本文件
- Linux监控系统磁盘使用比例,当使用率达到指定比例,删除指定目录下的所有文件的shell脚本
- 通过递归查询指定目录下的所有文件和子文件夹下的指定文件名
- AIX 删除指定目录、指定后缀、指定天数以前的历史文件
- shell 定时删除某个目录指定格式文件(递归)
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- windows中无法删除文件,报"无法删除****,找不到指定文件,请确定指定的路径及文件名是否正确"的解决
- 检查当前目录下是否存在指定的文件,如果存在就重新命名
- linux下编写shell获取指定目录下的文件名
- shell判断文件,目录是否存在或者具有权限
- java小程序,用java在指定目录或以及子目录中找出同名文件,java File过滤文件名后找同名文件
- 根据字段状态删除指定目录文件的shell脚本
- shell判断文件,目录是否存在或者具有权限
- 得到一个指定目录下所有文件的文件名,子目录名不要
- javase——递归获取指定目录下(包括子目录)指定后缀的文件的文件名
- 通过递归查询指定目录下的所有文件和子文件夹下的指定文件名
- shell 脚本 打印指定目录下包含某些字符串的文件