Anno domini 2024 Sun, 22 Sep 19:56:05 +0000
dep via tde-users scripsit:
Some months ago I asked here if there were a way to
log my ISP's downtime,
and got a useful answer. Today I've been attempting to refine it a bit,
and there is some progress, but not success.
Here's what I have:
[code]
#!/bin/bash
#monitor frontier communications downtime
ping -i 3 -O -D 1.1.1.1 | while read row
do
awk '{ sub(/[0-9]{10}/, strftime("%Y-%m-%d %H:%M:%S", substr($0,2,10)))
}
1' <<< "$row"| tee ~/frontier_downtime.log
done
[/code]
Most of it is simply converting internet time to human time, because I
might have to use it to support a complaint. It runs fine in a terminal, a
nice ping and result every three seconds, but only writes the first line,
the first ping result, to the logfile. (And yes, ir's probably sloppy.)
What do I have wrong?
Bonus question: any way to keep it running with the terminal closed? I
can't even use & to free the terminal; I'd like to start the thing and
have it cook merrrily away without a terminal open or even minimized, and
use top or killall to dispose of it if that becomes necessary.
I'm pretty sure I'm missing something obvious.
In case you did not solve this already:
$ ping -i 3 -O -D 1.1.1.1 |\
stdbuf -i 0 -o 0 awk '{ sub(/[0-9]{10}/, strftime("%Y-%m-%d %H:%M:%S",
substr($0,2,10))) } 1' |\
tee -a ~/frontier_downtime.log
You can put this line in /etc/rc.local and it will do it's work in the background.
Nik
--
Please do not email me anything that you are not comfortable also sharing with the NSA,
CIA ...