標籤:function message online 簡訊
#!/bin/bash#-------------------------------------------------- #Created:2015-04-27#Author:jimmygong#Mail:[email protected]#Function:check core && send message#Version:1.0#--------------------------------------------------set -o nounsetset -o errexitonlinedir="/opt/online"tellist=(1234567891212345678913)function sendmessage () {currdate="$(date +%Y/%m/%d)"[email protected]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>&1done}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 donedone}checkcoreexit 0============================說明======================================目錄結構ll /opt/online/drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.11drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.22drwxr-xr-x 2 root root 4096 2015-04-27 18:20 online.33touch /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 corefilecat /opt/online/online.11/corefile core.111執行第2次時就不會再傳送簡訊和寫入到這個corefile檔案裡了。[email protected]也可以寫成message=""[email protected] #所有的位置參數(每個都作為獨立的字串) 等同於"$1" "$2"... "$N"。set -o nounset #在擴充一個沒有的設定的變數的時候,顯示錯誤的資訊 set -o errexit #如果一個命令返回一個非0退出狀態值(失敗),就退出.num=`ls -1` # -1 list one file per line效果ls -1 /opt/online/online.11online.22online.33需要安裝links(apt-get -y install links或yum -y install links)
本文出自 “7928217” 部落格,請務必保留此出處http://7938217.blog.51cto.com/7928217/1639520
檢查某個服務產生core檔案只發送1次簡訊,相同的core不發送(shell)