清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #!/bin/sh # halt command HALT=halt ping_forever_host(){ IP=$1 time_out=$2 count=3 kernel=` uname -s` total_miss=0 echo "ups check host '${IP}' for (${time_out}) seconds, [forever mode]" # ping host, if miss recieved packets, then add to total_miss while true do case $kernel in VMkernel) #esxi 5.1 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) packets received,.*/\1/'` ;; Darwin) #MacOS X 10.7.4 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) packets received,.*/\1/'` ;; Linux) #ubuntu 12.04 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) received,.*/\1/'` ;; *) echo "Unknown Architecture $kernel" exit 1 ;; esac miss=$((count-ret)) if [ $miss - eq $count ]; then total_miss=$((total_miss+miss)) echo "total_miss: ${total_miss} --> ${time_out}" else total_miss=0 fi # if miss count over limit, then halt the computer!!! if [ $total_miss - ge $time_out ]; then echo "SYSTEM WILL HALT AT '`date`'!!!" ${HALT} break ; fi done } ping_once_host(){ IP=$1 count=$2 time_out=$2 kernel=` uname -s` total_miss=0 echo "ups check host '${IP}' for (${time_out}) seconds, [once mode]" # ping host, if miss recieved packets, then add to total_miss case $kernel in VMkernel) #esxi 5.1 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) packets received,.*/\1/'` ;; Darwin) #MacOS X 10.7.4 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) packets received,.*/\1/'` ;; Linux) #ubuntu 12.04 ret=` ping -c ${count} -W 1 ${IP} 2& gt ;&1| grep 'packets transmitted'| sed 's/.*, \(.*\) received,.*/\1/'` ;; *) echo "Unknown Architecture $kernel" exit 1 ;; esac miss=$((count-ret)) if [ $miss - eq $count ]; then total_miss=$((total_miss+miss)) echo "total_miss: ${total_miss} --> ${time_out}" else total_miss=0 fi # if miss count over limit, then halt the computer!!! if [ $total_miss - ge $time_out ]; then echo "SYSTEM WILL HALT AT '`date`'!!!" ${HALT} fi } main(){ action=$1; case $action in forever) #run forever ping_forever_host $2 $3 ;; once) # run once ping_once_host $2 $3 ;; *) echo "usage: sudo ./ups_check forever 192.168.2.1 120" echo "usage: sudo ./ups_check once 192.168.2.1 60" exit 1 ;; esac } main $1 $2 $3 |