In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to write a Shell script to detect the smooth flow of a certain ip network". In the daily operation, I believe that many people have doubts about how to write a Shell script to detect the smooth flow of a certain ip network. I have consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to write a Shell script to detect the smooth flow of a certain ip network". Next, please follow the editor to study!
The code is as follows:
#! / bin/bash
#
# the script is placed on a different machine. Use the scheduled task to check whether the network of 192.168.10.231 is unblocked, and send SMS alarm if it is not available.
# to prevent frequent receipt of SMS messages, the following restrictions are imposed on sending SMS messages:
# only send the first three alarm messages in an hour, that is, if the network is not available, only the first three messages will be sent in an hour.
# this script can only detect whether one ip is disconnected. You can add a loop at the beginning to detect multiple ip
#
# initialize environment variables
Source / root/.bash_profile
# mailing list
Mail_list='135xxxxxxxx@139.com,zhangwz@xx.net'
# ip detected by ping three times
Ping= `ping-c 3 192.168.1.69 | awk 'NR==7 {print $4}' `
# if there is no ping connection three times, do the following
If [$ping-eq 0]
Then
# check whether the mailinfo file exists. If it does not exist, create it.
If [!-e. / mailinfo]
Then
Touch. / mailinfo
Fi
# get the current host time, which is used to display the time of the message body
Now_time= `date`
# check whether the number of lines in. / mailinfo is empty, and send email directly if it is empty
Row_num= `wc-l. / mailinfo | cut-c 1`
If [$row_num-eq 0]
Then
Echo "send email"
Echo-e "1.69 network has been disconnected, please check\ n\ nalarm time: $now_time" | mutt-s "1.69 alarm" $mail_list
# update the last time sent
Date +% Y%m%d-%H%M >. / mailinfo
Echo 1 > >. / mailinfo
# if the mailinfo content is not empty, determine whether the current time minus 1 hour is greater than the last time it was sent, and if so, send an email
Else
# get the date and time of the last email
Last_date= `head-1. / mailinfo | cut-c 1-8`
Last_time= `head-1. / mailinfo | cut-c 10-13`
# get the date and time of 1 hour ago
Current_date= `date +% Y% m% d`
Current_time= `date +% H% M`
# calculate the difference between the current time and the last time. Add 10 # to prevent characters starting with 0 from being calculated as octal.
Let time_diff=10#$current_time-10#$last_time
# get the number of times sent
Send_times= `tail-1. / mailinfo`
# send email in the following four ways:
# current date > last date, you can send it, and then send count send_times set to 1
If ["$current_date"-gt "$last_date"]
Then
Echo "send email"
Echo-e "1.69 network has been disconnected, please check\ n\ nalarm time: $now_time" | mutt-s "1.69 alarm" $mail_list
# update the last time sent
Date +% Y%m%d-%H%M >. / mailinfo
Echo 1 > >. / mailinfo
Fi
# the current date is equal to the last date and. If this time is less than 1 hour, you can send it, and then set the send count send_times to 1.
If ["$current_date"-eq "$last_date"-a $time_diff-ge 100]
Then
Echo "send email"
Echo-e "1.69 network has been disconnected, please check\ n\ nalarm time: $now_time" | mutt-s "1.69 alarm" $mail_list
# update the last time sent
Date +% Y%m%d-%H%M >. / mailinfo
Echo 1 > >. / mailinfo
Fi
# current date equals last date and send count send_times is set to 1, can be sent, and then send times plus 1
If ["$current_date"-eq "$last_date"-a $send_times-eq 1]
Then
Echo "send email"
Echo-e "1.69 network has been disconnected, please check\ n\ nalarm time: $now_time" | mutt-s "1.69 alarm" $mail_list
# update the last time sent
Date +% Y%m%d-%H%M >. / mailinfo
Echo 2 > >. / mailinfo
Fi
# current date equals last date and send count send_times is set to 2, can be sent, and then send times plus 1
If ["$current_date"-eq "$last_date"-a $send_times-eq 2]
Then
Echo "send email"
Echo-e "1.69 network has been disconnected, please check\ n\ nalarm time: $now_time" | mutt-s "1.69 alarm" $mail_list
# update the last time sent
Date +% Y%m%d-%H%M >. / mailinfo
Echo 3 > >. / mailinfo
Fi
Fi
Fi
At this point, the study on "how to write a Shell script to detect the smooth flow of an ip network" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.