Shell Scripts-Monitor network conditions

Source: Internet
Author: User

#!/bin/bash# -------------------------------------------------------------------------------#  filename:    networkchecking# revision:    2.0# date:         2017/09/14# author:      xad#  Email:       [email protected]# Website:      http://onenice.blog.51cto.com/# description: check network and sendmail  to XAD , wirte executing log# Notes:        ~# -------------------------------------------------------------------------------# copyright:    2017 (c) xad# license:     gpldomain1=www.baidu.comdomain2= Www.google.comDATE= ' date  "+%f %h:%m:%s" ' host= ' hostname ' ipaddress= ' ifconfig eth0| grep   "INET ADDR:"  | awk -f[: " "]+  ' {print $4} ' # #打印成功日志 # #log_info () {    if [ !  -x /var/log/$0 ];then        mkdir /var/log/$0     fi        echo  "$DATE   $HOST  $ ipaddress  $USER  execute  $0 >> $1 " >> /var/log/$0/ success.log}# #打印错误日志 # #log_error () {    if [ ! -x /var/log/$0 ]; then        mkdir /var/log/$0    fi         echo  $DATE   $HOST   $IPADDRESS   $USER  execute  $0 >> $1 " >>/var/log/$0/error.log}# #检测网络是否通畅 # #check_network () {     ping -c 2  $DOMAIN 1 > /dev/null    pingstatus1=$?     echo -n&nBSP; $pingstatus 1 > /tmp/netwok-status    if [  $pingstatus 1 -eq  0 ];then        log_info  "network to $ Domain1 is ok "    else        log_error   "network to  $DOMAIN 1 is error"     fi         ping -c 2  $DOMAIN 2 > /dev/null     pingstatus2=$?    echo -n  $pingstatus 2 >> /tmp/netwok-status     if [  $pingstatus 2 -eq 0 ];then         log_info  "network to  $DOMAIN 2 is ok"     else         log_error  "network to  $DOMAIN 2 is  Error "    fi}# #发Send alert message and output send log # #sendmail () {    status= ' cat /tmp/netwok-status '      if [  "$STATUS"  -eq 11 ]; then         echo  "Time: $DATE  hostname: $HOST  ip: $IPADDRESS  Network is normal! "  |  mail -s  "please check your network now!"  [email protected]        if [ $? -eq 0  ];then            echo  "$DATE  $ host  $IPADDRESS   $USER  >> sendmail is ok ! "  >> /var/log/$0/sendmail.log        else             echo  "$DATE   $HOST   $IPADDRESS  $ user >> sendmail is error ! "  >> /var/log/$0/sendmail.log        fifi}check_networksendmail 


This article is from the "Top-one" blog, make sure to keep this source http://onenice.blog.51cto.com/13201315/1965399

Shell Scripts-Monitor network conditions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.