1

my first post here.

I made an script that provide reports of my network every 5 minutes. The script is simple and is working fine except when there is issues in my network. The script is running in Ubuntu Server 18.04.

My line for the Ping command is:

ping -w 300 192.168.1.216

The issue consist when I am having packet losses, ping stop immediately an doesn't finish the 300 seconds (5 minutes) run. I checked online and everywhere but I haven't been able to find a solution to make the ping keep running when there are lost packets. This is an example:

ping -w 300 192.168.1.216
PING 192.168.1.216 (192.168.1.216) 56(84) bytes of data.
64 bytes from 192.168.1.216: icmp_seq=1 ttl=128 time=2.29 ms
64 bytes from 192.168.1.216: icmp_seq=2 ttl=128 time=4.14 ms
64 bytes from 192.168.1.216: icmp_seq=3 ttl=128 time=17.9 ms
64 bytes from 192.168.1.216: icmp_seq=4 ttl=128 time=40.6 ms
64 bytes from 192.168.1.216: icmp_seq=5 ttl=128 time=38.6 ms
From 192.168.1.2 icmp_seq=30 Destination Host Unreachable
From 192.168.1.2 icmp_seq=31 Destination Host Unreachable
From 192.168.1.2 icmp_seq=32 Destination Host Unreachable

--- 192.168.1.216 ping statistics ---
33 packets transmitted, 5 received, +3 errors, 84% packet loss, time 32657ms
rtt min/avg/max/mdev = 2.295/20.738/40.659/16.379 ms, pipe 4

Thanks.


EDIT REASON: Add full script code.

Full script code:

Location="XXX"
host="192.168.6.1"

while true
do
    result=$(ping -w 300 -q $host)

    sendemail                                               \
            -f "[email protected]"                             \
            -u "XXX 5 Minutes Network Report"               \
            -t "[email protected]"                       \
            -s "smtp.gmail.com:587"                         \
            -o tls=yes                                      \
            -xu "[email protected]"                            \
            -xp "password"                                  \
            -m "$result"
done

This is to check the status of our VPN. Like I said is a very simple script. I am using the ping -c 1 as suggested for an emergency one that will let us know if there is connectivity issues in the VPN as soon as possible.

2
  • 1
    Welcome to Ask Ubuntu. I don't understand what you're trying to do, but the -w appears to be doing what it should as the man ping states "it waits either for deadline expire or until count probes are answered or for some error notification from network." - ie. it's stopping because last condition is reached as I understand your question. When I've had to do similar to you, I sent a single ping -c 1 & then processed according to error.code err1721=$? in subsequent lines.
    – guiverc
    Dec 4, 2018 at 22:24
  • All that I need is to have a ping running for 300/3600/86400 seconds, that is why I used the -w. What I need is a way that ping doesn't stop when there are network errors when using the -w or another way to make sure it runs for the specific amount of time disregarding network errors, packet lost etc.
    – Mr.Alvaro
    Dec 4, 2018 at 22:33

1 Answer 1

1

I would consider changing your script to run ping -c 1 <ip-address> every five minutes, instead of relying on the ping binary to provide that behavior. Then you can also check the return status ($?) to determine if it succeeded or failed.

It would be helpful if you also post your script, so that the context of your problem can be more easily understood.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .