#!/bin/bash #-------------------------------------------------- #Created:2015-04-27 #Author:jimmygong #Mail:jimmygong@taomee.com #Function:check core && send message #Version:1.0 #-------------------------------------------------- set -o nounset set -o errexit onlinedir="/opt/online" tellist=(12345678912 12345678913 ) function sendmessage () { currdate="$(date +%Y/%m/%d)" message=$@ ip=`ifconfig eth1|awk ‘/inet addr:/‘|awk -F: ‘{print $2}‘|awk -F" " ‘{print $1}‘` for phone in ${tellist[@]} do links -dump "http://192.168.1.1/22222?mobile=$phone&msg=$currdate:$message:$ip&sign=11111111111111111111111111111111" > /dev/null 2>&1 done } function checkcore() { num=`ls -1 $onlinedir|grep "^online"|wc -l` for ((k=1;k<=${num};k++)) do listdir=`ls -1 $onlinedir|grep "^online"|sed -n $k‘p‘` for j in $onlinedir/$listdir do cd $j touch corefile for m in core.* do if [[ -e $m ]] then core=0 for f in `cat $j/corefile` do if [[ $m = $f ]] then core=1 break fi done if [[ $core -eq 0 ]] then message="core" sendmessage $message echo $m >> $j/corefile fi fi done done done } checkcore exit 0 ============================说明====================================== 目录结构 ll /opt/online/ drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.11 drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.22 drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.33 touch /opt/online/online.11/core.111 执行第1次脚本后会 ll /opt/online/online.11/ -rw-rw-r--. 1 root root 0 Apr 27 22:05 core.111 -rw-rw-r--. 1 root root 9 Apr 27 23:27 corefile cat /opt/online/online.11/corefile core.111 执行第2次时就不会再发送短信和写入到这个corefile文件里了。 message=$@也可以写成message="" $@ #所有的位置参数(每个都作为独立的字符串) 等同于"$1" "$2"... "$N"。 set -o nounset #在扩展一个没有的设置的变量的时候,显示错误的信息 set -o errexit #如果一个命令返回一个非0退出状态值(失败),就退出. num=`ls -1` # -1 list one file per line 效果 ls -1 /opt/online/ online.11 online.22 online.33 需要安装links(apt-get -y install links或yum -y install links)
本文出自 “7928217” 博客,请务必保留此出处http://7938217.blog.51cto.com/7928217/1639520
检查某个服务产生core文件只发送1次短信,相同的core不发送(shell)
原文地址:http://7938217.blog.51cto.com/7928217/1639520