Answer the question
In order to leave comments, you need to log in
How to make an internet loss notification with ubuntu?
Hello. Please tell me how to implement this task:
There is a server with ubuntu 20.04 on Oracle and a home Mikrotik with a static IP (let's say 100.120.30.100).
It is necessary that the Oracle server ping IP 100.120.30.100 with a frequency of 1 minute and:
1. If the ping goes (for example, for 3000ms), do nothing yet.
2.If the ping does not go, send a notification once (and not spam every minute) via telegram (just open the pre-created link N1 through its api)
3.If the ping reappears, send a notification once via telegram to the pre-created link N2.
And so on in a circle (There is a ping-1 notification, no ping-2 notification, etc.)
I will be very grateful for the answer
Answer the question
In order to leave comments, you need to log in
I was looking for a similar script to run through cron every minute and so as not to "spam" constantly
here is the script
#!/bin/bash
HOSTS="google.com 8.8.4.4"
SUBJECT="Host Down"
ping_attempts=1
down_hosts=/stuff/scritp/down_hosts.txt
for myHost in $HOSTS
do
count=$(ping -c $ping_attempts $myHost | awk -F, '/received/{print $2*1}')
if [ $count -eq 0 ]; then
if [ $(grep -c "$myHost" "$down_hosts") -eq 0 ]; then
/usr/bin/curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d chat_id=123 -d text="$myHost ping FAILED at $(date)" > /dev/null 2>&1
echo "$myHost" >> $down_hosts
fi
else
if [ $(grep -c "$myHost" "$down_hosts") -eq 1 ]; then
/usr/bin/curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d chat_id=123 -d text="$myHost ping OK at $(date)" > /dev/null 2>&1
sed -i "/$myHost/d" "$down_hosts"
fi
fi
done
Well, write a simple script that would put the state into some file and periodically compare its contents with the results of the ping. Conditionally, if the file is 0, and the ping goes on - report. If there is 1 in the file, but the ping does not go - too.
The options are:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question