Looking for some greatly appreciated help writing a shell script on OpenWRT. I want the script to check ping response times for an OpenVPN connection and if the response time in ms goes over a certain threshold to then perform an action such as change the configuration file to connect to a different OpenVPN server. I will set the script up via crontab on the OpenWRT firewall.
So far I have worked out the command to get the ping result in ms that I need for the query.
ping -c 1 1.1.1.1 | awk 'FNR == 2 { print $(NF-1) }' | cut -d'=' -f2
This will ping the IP address (in this instance Cloudfare DNS) and print the ping ms time to the screen.
I can also modify this command to write the value to a file instead by using stdbuf
ping -c 1 1.1.1.1 | awk 'FNR == 2 { print $(NF-1) }' | stdbuf -o0 cut -d'=' -f2 > pingms
I need some help on then taking this value either via stdout or output to a text file and performing an action if the value is greater than say 100ms.
eg. if value is greater than 100ms (from command above) then execute additional command / script, otherwise do nothing
Any help would be appreciated.
Thanks