Re: Script genius needed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
____________________________________________________
tde-users mailing list -- users@xxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxx
Web mail archive available at https://mail.trinitydesktop.org/mailman3/hyperkitty/list/users@xxxxxxxxxxxxxxxxxx



[Index of Archives]     [Trinity Devel]     [KDE]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]     [Trinity Desktop Environment]

  Powered by Linux