檢查某個服務產生core檔案只發送1次簡訊,相同的core不發送(shell)

來源:互聯網
上載者:User

標籤: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)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.