[转]shell脚本自动监控日志文件,发现关键词发送邮件模板
(2013-03-04 16:34:35)| 分类: 工作 |
monitor
#!/bin/bash
#Usage: Excute the java class and remove the specified productname file #
#author:#
#2009.11.01#
#Specife this file usage
usage(){
echo
"####################################################"
echo "# Monitor xxx.log and send info to
DBA
#"
short_usage
}
short_usage(){
echo "# Usage: ./monitor -p
filepath
#"
echo
"####################################################"
exit
1
}
#检测和获取参数
if [ $# = 0 ];then
usage
fi
while getopts p: OPTION
do
case $OPTION in
p)filepath=$OPTARG
;;
\?)usage
;;
esac
done
mail_to=yourmail@xx.xx
mail_file=archive_alarm
echo "`date "+%Y-%m-%d %H:%M:%S"` " > $mail_file
if cat $filepath| grep -q "keyword";then
echo keyword
>>
$mail_file
fi
if [ [ -f $mail_file ] ] ; then
cat
$mail_file | mail -s "alarm " $mail_to
fi
#!/bin/bash
#Usage: Excute the java class and remove the specified productname file #
#author:#
#2009.11.01#
#Specife this file usage
usage(){
}
short_usage(){
}
#检测和获取参数
if [ $# = 0 ];then
fi
while getopts p: OPTION
do
case $OPTION in
esac
done
mail_to=yourmail@xx.xx
mail_file=archive_alarm
echo "`date "+%Y-%m-%d %H:%M:%S"` " > $mail_file
if cat $filepath| grep -q "keyword";then
if [ [ -f $mail_file ] ] ; then
fi

加载中…