while true; do (stdbuf -i0 -o0 -e0 nmap -Pn -p 80 google.co.in; sleep 1) > /dev/stdout 2>/dev/null | stdbuf -i0 -o0 -e0 grep --line-buffered "Nmap done" | while IFS= read -r line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done; done | stdbuf -i0 -o0 -e0 tee -a ping.txt | stdbuf -i0 -o0 -e0 grep --line-buffered "in [^0].* seconds\| 0 IP" | stdbuf -i0 -o0 -e0 sed -e "s/0 IP addresses.*/Network is unreachable/g" | stdbuf -i0 -o0 -e0 tee -a ping2.txt


it generates 2 files:

ping.txt -> this will have nmap result for every second. If it says "0 IP addresses" then network is down. Also if the time taken can be seen to see if it is slow

ping2.txt -> this will have messages taken from ping.txt but only when there is an issue not for every second. Also the messages will show time and when down, a message saying "network is unreachable"

When there are issues which are difficult to be shown when the technician is there, we can use the above script to record and show the issue.


Note: It assumes you have broadband with sufficient speed and nmap takes less than 1 second to scan google.co.in