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.
On Sun, Sep 22, 2024 at 19:56 (+0000), dep via tde-users wrote:
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.)
I don't think that is true. I think it is writing the most recent ping result to the log file.
What do I have wrong?
You didn't use the '-a' option to tee. So each invocation of tee over-writes the file with the most recent line.
I might suggest something like
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" done | tee -a ~/frontier_downtime.log
to avoid calling a new invocation of tee for every ping result.
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.
I think maybe you are.
touch ~/frontier_downtime.log 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" done >> ~/frontier_downtime.log &
You should be able to close that terminal after running that without anything bad happening. And if you want to see that is going on from some terminal, you can use tail -f ~/frontier_downtime.log in that terminal.
Cheers. Jim
On Sun, Sep 22, 2024 at 18:23 (-0300), Jim via tde-users wrote:
On Sun, Sep 22, 2024 at 19:56 (+0000), dep via tde-users wrote:
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.)
I don't think that is true. I think it is writing the most recent ping result to the log file.
What do I have wrong?
You didn't use the '-a' option to tee. So each invocation of tee over-writes the file with the most recent line.
I might suggest something like
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" done | tee -a ~/frontier_downtime.log
to avoid calling a new invocation of tee for every ping result.
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.
I think maybe you are.
touch ~/frontier_downtime.log 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" done >> ~/frontier_downtime.log &
You should be able to close that terminal after running that without anything bad happening. And if you want to see that is going on from some terminal, you can use tail -f ~/frontier_downtime.log in that terminal.
After I sent that off, it occurred to me that you don't need a while loop at all...
These two commands should all be on one line, just in case your mail reader breaks the lines.
ping -i 3 -O -D 1.1.1.1 | awk '{ sub(/[0-9]{10}/, strftime("%Y-%m-%d %H:%M:%S", substr($0,2,10))) } 1' | tee -a ~/frontier_downtime.log
Have you thought about losing the microseconds? It probably isn't all that interesting.
ping -i 3 -O -D 1.1.1.1 | awk '{ sub(/[0-9]{10}.[0-9]{6}/, strftime("%Y-%m-%d %H:%M:%S", substr($0,2,10))) } 1' | tee -a ~/frontier_downtime.log
Jim
said Jim via tde-users: | On Sun, Sep 22, 2024 at 18:23 (-0300), Jim via tde-users wrote: | > On Sun, Sep 22, 2024 at 19:56 (+0000), dep via tde-users wrote: | >> 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.) | > | > I don't think that is true. I think it is writing the most recent | > ping result to the log file. | > | >> What do I have wrong? | > | > You didn't use the '-a' option to tee. So each invocation of tee | > over-writes the file with the most recent line. | > | > I might suggest something like | > | > 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" | > done | tee -a ~/frontier_downtime.log | > | > to avoid calling a new invocation of tee for every ping result. | > | >> 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. | > | > I think maybe you are. | > | > touch ~/frontier_downtime.log | > 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" | > done >> ~/frontier_downtime.log & | > | > You should be able to close that terminal after running that without | > anything bad happening. And if you want to see that is going on from | > some terminal, you can use | > tail -f ~/frontier_downtime.log | > in that terminal. | | After I sent that off, it occurred to me that you don't need a while | loop at all... | | These two commands should all be on one line, just in case your mail | reader breaks the lines. | | ping -i 3 -O -D 1.1.1.1 | awk '{ sub(/[0-9]{10}/, strftime("%Y-%m-%d | %H:%M:%S", substr($0,2,10))) } 1' | tee -a ~/frontier_downtime.log | | Have you thought about losing the microseconds? It probably isn't all | that interesting. | | ping -i 3 -O -D 1.1.1.1 | awk '{ sub(/[0-9]{10}.[0-9]{6}/, | strftime("%Y-%m-%d %H:%M:%S", substr($0,2,10))) } 1' | tee -a | ~/frontier_downtime.log
Thanks very much. The last one that works here does contain the while. Though getting rid of the microseconds is, yes, something I'd wished for, I didn't know the syntax to do it. I still don't, apparently!
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
dep via tde-users users@trinitydesktop.org writes:
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.
Why use a script, does your linux setup have a program called 'uptimes' (in Debian) which uses the command `uprecords` which gives your longest uptimes and your cumulative uptimes and your cumulative downtimes.
Does this help?
Thanks Sharon. - -- A taste of linux = http://www.sharons.org.uk TGmeds = http://www.tgmeds.org.uk DrugFacts = https://www.drugfacts.org.uk Debian 12.7, Fluxbox 1.3.7, emacs 31.0.50, org 9.7.11
said Sharon Kimble via tde-users:
| Why use a script, does your linux setup have a program called 'uptimes' | (in Debian) which uses the command `uprecords` which gives your longest | uptimes and your cumulative uptimes and your cumulative downtimes.
I have "uptime," which renders a one-line summary of how long the computer has been on, the load, etc., but is silent on connections. I have no "uprecords" or "uprecord." I've looked at a variety of tools. Apparently "gping" is no longer maintained; the Gnome tools don't log and don't allow anything except the Linux ping default, which is once per second. I looked at, installed, and tried unsuccessfully to configure "Smokeping," which is like bringing in a battle tank to get rid of a wasp nest. I had hoped that there would be some lightweight utility that would include what I wanted, which is a record of the times my ISP fails to PIS, as proof of their unreliability, chapter and verse. It seems to have turned out that a script does this when nothing else does.
(It performed during one of the failures earlier today.)
I've thrown it and the log in a little ~/ subdirectory, stuck an icon on it and put it in Kmenu. So one click and it is running, and I can always monitor it by looking at the terminal that's generated. In that it generated more than a megabyte of log per day, I'd like to cook up a way to automate archiving of the existing log, with date, daily. As it is, I can just move the file into an archive subdirectory and rename it at whatever frequency, probably weekly, I'd like. Then, when it's needed, it will be simple to provide a list of times it's been down, to within three seconds.
| Does this help?
It's good to know -- I was unaware of the utility -- but in this case it doesn't do what I need.
Thanks.
said jacobheinrich--- via tde-users:
| Why not use a network monitoring tool like Nagios?
Too much tool for the task, don't you think? My goal is a list of ISP downtimes over a period of time, with logs to prove it.
I mean yeah, its a powerful tool, but I use it for the exact thing youre talking about. When a device or network in my homelab goes down, I get allerted and its logged. I use it to track outages of my WAN too.
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 ...
said Dr. Nikolaus Klepp via tde-users:
| 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
Thanks, Nik. I have my little script chugging along -- unfortunately, Frontier Communications has offered many proofs that it works. After a sufficient amount of time -- a month, I think, would be fine -- I'll be able to send a complaint to the FCC, who would have to approve the proposed sale of Frontier to Verizon. It might interest the FCC to know that Frontier still hasn't done the improvements that the government paid them to do years ago. The routine seems to be: Frontier gets lots of money. Frontier declared bankruptcy and gets the debt excused. Frontier gets more money. Frontier sells out to Verizon. In every step, they don't do anything it was paid to do. They don't even replace the backup batteries, so if the power blinks for a millisecond, not even long enough to make the clocks flash, their internet and phone services go down and don't come back for half an hour. The log is to demonstrate how bad they are.
| You can put this line in /etc/rc.local and it will do it's work in the | background.
Thanks very much. I may do this.