summarylogtreecommitdiffstats
path: root/pingpong.sh
blob: c8caf871bf6173f14b2f9f8f75e64323f349350f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

while true; do
    # Use the ping command to check the response time
    response_time=$(ping -c 1 8.8.8.8 | grep "time=" | cut -d' ' -f7 | cut -d'=' -f2)

    if [ -z "$response_time" ]; then
        # If response_time is empty, it means a timeout occurred
        echo "💩💩💩💩💩 Internet Outages"
    elif (( $(echo "$response_time > 150" | bc -l) )); then
        # If response_time is greater than 100 ms, print "Bad connection" message
        echo "🔴🔴🔴🔴🔴 Bad connection: ${response_time} ms"
    else
        # If response_time is less than or equal to 100 ms, print "Normal connection" message
        echo "🟢🟢🟢🟢🟢 Normal connection: ${response_time} ms"
    fi

    # Sleep for 5 seconds before the next iteration
    sleep 5
done