Shell Script for rebooting if network down for a certain amount of time?

Compare the total packets vs the ones that are bad. netstat -i provides also good summary, compare all vs bad ones. Bad cabling would definitely yield errors.

Not seeing anything unusual so far (I guess):

Code:
# netstat -ss
tcp:
    4224773 packets sent
        2687768 data packets (2886450952 bytes)
        1043 data packets (1079989 bytes) retransmitted
        95 data packets unnecessarily retransmitted
        1532746 ack-only packets (275516 delayed)
        14 window probe packets
        438 window update packets
        3179 control packets
    3983760 packets received
        1150531 acks (for 2886417599 bytes)
        2802 duplicate acks
        2886221 packets (3452783958 bytes) received in-sequence
        233 completely duplicate packets (181928 bytes)
        17 old duplicate packets
        12278 out-of-order packets (14748023 bytes)
        94 window update packets
        73 packets received after close
    1978 connection requests
    39 connection accepts
    15 bad connection attempts
    1 ignored RSTs in the window
    1240 connections established (including accepts)
        469 times used RTT from hostcache
        469 times used RTT variance from hostcache
        366 times used slow-start threshold from hostcache
    2177 connections closed (including 21 drops)
        497 connections updated cached RTT on close
        497 connections updated cached RTT variance on close
        372 connections updated cached ssthresh on close
    253 embryonic connections dropped
    1150531 segments updated rtt (of 638001 attempts)
    502 retransmit timeouts
    15 persist timeouts
    4323 keepalive timeouts
        11 keepalive probes sent
    322898 correct ACK header predictions
    2625179 correct data packet header predictions
    44 syncache entries added
        6 retransmitted
        39 completed
        3 reset
        2 stale
    44 cookies sent
    49 hostcache entries added
    336 SACK recovery episodes
    705 segment rexmits in SACK recovery episodes
    686944 byte rexmits in SACK recovery episodes
    4676 SACK options (SACK blocks) received
    19205 SACK options (SACK blocks) sent
TCP connection count by state:
    16 connections in LISTEN state
    29 connections in ESTABLISHED state
    3 connections in FIN_WAIT_2 state
    1 connection  in TIME_WAIT state
udp:
    564 datagrams received
    12 with no checksum
    27 dropped due to no socket
    537 delivered
    535 datagrams output
ip:
    3985190 total packets received
    3984347 packets for this host
    843 packets not forwardable
    4227567 packets sent from this host
icmp:
    27 calls to icmp_error
    Output histogram:
        echo reply: 5
        destination unreachable: 27
    Input histogram:
        destination unreachable: 20
        echo: 5
        time exceeded: 6
    5 message responses generated
    ICMP address mask responses are disabled
igmp:
arp:
    8 ARP requests sent
    595 ARP requests received
    7 ARP replies received
    602 ARP packets received
ip6:
    13 total packets received
    13 packets for this host
    18 packets sent from this host
    14 output packets discarded due to no route
    3 multicast packets which we don't join
    Input histogram:
        TCP: 10
        ICMP6: 3
    Mbuf statistics:
        13 one mbuf
        0 one ext mbuf
        0 two or more ext mbuf
    13 failures of source address selection
    source addresses on an outgoing I/F
        3 link-locals
    source addresses on a non-outgoing I/F
        13 addresses scope=0xf
    source addresses of a different scope
        3 link-locals
    Source addresses selection rule applied:
        3 first candidate
        13 same address
icmp6:
    Output histogram:
        router solicitation: 3
        neighbor solicitation: 1
        MLDv2 listener report: 4
    Histogram of error messages to be generated:
rip6:

# netstat -i
Name    Mtu Network       Address              Ipkts Ierrs Idrop    Opkts Oerrs  Coll
re0    1500 <Link#1>      xx:xx:xx:xx:xx:x   4002488     0     0  7269742     0     0
re0       - xxxx::%re0/64 xxxx::xxxx:xxxx:x        0     -     -        5     -     -
re0       - xx.xxx.xx.x/2 server             4001034     -     -  4244571     -     -
lo0   16384 <Link#2>      lo0                     55     0     0       55     0     0
lo0       - localhost     localhost               10     -     -       10     -     -
lo0       - xxxx::%lo0/64 xxxx::x%lo0              0     -     -        0     -     -
lo0       - your-net      localhost               45     -     -       45     -     -
 
I have attached a network watchdog script.

It's actually from my firewall. It watches my ppp connection to the Internet, and runs on Raspbian Linux (Debian).

But I have ripped out all the firewall-specific code and ported to FreeBSD, so should be pretty close to what you asked for originally.

Might buy you some breathing space while you troubleshoot the cause (suggest you change the ping targets).

[I had to add a ".txt" suffix to attach it...]
 

Attachments

  • internet_watchdog.txt
    3.5 KB · Views: 96
the file contains the word "systemd"
open at your own risk
/s
There's an alarming lack of objective analysis in that statement.

I expect that most people would understand that its written to be portable with minimal editing. Its prime targets are Debian, and Devuan, and it was ported to work on FreeBSD. If you only ever want it to work on FreeBSD, then it's an extremely simple task to remove the completely benign references to systemd. I tested on FreeBSD, but left all the Debian code visible in the script so it would be universally adaptable.
 
Back
Top