blob.png

#!/bin/bash
IP=219.149.213.202
Ping=/bin/ping
Mail=/bin/mail
Ps=/bin/ps
lock(){
  shell_name="$(basename $0)"
  Thread=$($Ps -ef|grep "$shell_name"|wc -l)
  if [ $Thread -gt 3 ];then
    echo "$shell_name is running..."
    exit 1
  fi
}
mail_set() {
  Data="$1"
  echo "$Data"|$Mail -s "网络丢包 $(date)" 921069658@qq.com
}
main() {
  lock
  while true
  do
    Tail_data=$($Ping -c 100 $IP|tail -2|head -1)
    Value=$(echo $Tail_data|awk -F "[ ]+" '{print $6}')
    if [ "$Value" != "0%"  ];then
      mail_set "$Tail_data"
    fi
    sleep 20
  done
}
main