Scripting Eight: The Ping tool monitors multiple hosts simultaneously (running in the background and displaying)

Source: Internet
Author: User
Tags usleep

function: monitor multiple hosts in real time through ping work

implementation: multi-process background running, and sub-region display

use: to monitor the host as a parameter


Demonstrate:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/03/wKiom1cPhufCssuaAAAUPUnKXFw212.png "style=" float: none; "title=" 1.png "alt=" Wkiom1cphufcssuaaaaupunkxfw212.png "/>


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/00/wKioL1cPh6CR_wEcAAAwky7TshE279.png "style=" float: none; "title=" 2.png "alt=" Wkiol1cph6cr_wecaaawky7tshe279.png "/>



Code area:

#/bin/bash#  ly#  ------------------#  copyright 2016.04.14   lingyi  ([email protected])  QQ:1519952564#   "Monitor hosts by batch  ping in the background "all_sum=0 success_sum=0failed_sum=0failed_percent=0pids_arry= () signs_arry= () ips_arry= ([email protected]) line_start=5# show interval (rows) line_interval=1# background run function, Implement ping and print statistics in the specified area exec_func () {local stop_exec=falsetrap  ' stop_exec=true '  $3while !   $stop _exec; doping -c 1 -w 2 $1 &>/dev/null &&   (( success_sum+=1 ))  | |   (( failed_sum+=1 )) (( all_sum+=1 )) failed_percent=$ ( echo  "scale=2;${ failed_sum}/${all_sum}*100 " | bc ) echo -ne " \033[$2;1h "printf "      %-16s%-10s%-10s%-10s%-10s " $1  $all _sum  $success _sum  $failed _sum " ${failed _percent}% "usleep 1$ ((random%5)) 00000done} #捕捉信号 (general Ctrl + C), and ignore trap  '   '  2# hide mouse tput  civisclearprintf  "\n\t\t%s\n"   ' ping monitor [  "Q" &NBSP;TO&NBSP;EXIT&NBSP;!&NBSP;]  printf  "%57s\n"   '   '  | tr  '   '   ' = ' printf  '      %-16s%-10s%-10s%-10s%-10s\n " ip sum suc fail perc# cycle monitoring host, and record the process number of the background process, So that it is forbidden to run for (( index=0; index<${#ips_arry [@]}; index++ )) after the run is finished;  dosign=$ ((random%20+ ) (( line_start+=line_interval )) exec_func ${ips_arry[index]}  $line _start  $sign  &pids_arry= ( ${pids_arry[@]} $! ) signs_arry= ( ${signs_arry[@]}  $sign  ) usleep $ ((random%5+6)) 00000done# receive user run through "q" key   Terminate script while :; doread -s -n 1  user_inputif [[  $user _input ==  ' Q '  ]]; thenfor  ((index=0; index <${#ips_arry [@]}; index++ )) Dokill  -${signs_arry[index]} ${pids_arry[index]} &>/dev/nulldonetput cnormsleep  1echo -ne  "\033[$line _start;1h" Echoexitfidone




This article is from the "retrograde person" blog, please be sure to keep this source http://lingyi.blog.51cto.com/2837715/1763905

Scripting Eight: The Ping tool monitors multiple hosts simultaneously (running in the background and displaying)

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.