Follow

How do you check in a script for internet connectivity?

Kind of: If you have internet do your thing, else exit here and do nothing.

(My solution was a ping, but then I get `ping: sendmsg: No route to host` in my cronjobs.)

Okay. It seems to work with ping and `if [ $? -eq 0 ]`. I just did the wrong check.

@natedalliard I was using a dig command to measure internet connectivity and if so, also get the latency

#!/bin/sh

dig perso.pw @80.67.169.12 +timeout=1 > /tmp/latencecheck

if [ $? -eq 0 ]
then
time=$(awk '/Query time/{
if($4 < 60) { print "_";}
if($4 >= 60 && $4 <= 150) { print "-"; }
if($4 > 150) { print "¯"; }
}' /tmp/latencecheck)
echo $time | tee /tmp/latenceresult
else
echo "N" | tee /tmp/latenceresult
fi

@solene Thx a lot, I will try that!

(Btw. you are my personal OpenBSD hero — hmm, is there a female form of hero?! — here on Mastodon)

@natedalliard

#!/bin/sh
DOMAIN="openbsd.org"
PORT=443
nc -zw1 "$DOMAIN" $PORT > /dev/null 2>&1 && exit 0 || exit 1

dev.ybad.name/Scripts/mybin/ne

Sign in to participate in the conversation
chaos.social

chaos.social - because anarchy is much more fun with friends.
chaos.social is a small Mastodon instance for and by the Chaos community surrounding the Chaos Computer Club. We provide a small community space - Be excellent to each other, and have a look at what that means around here.
Follow @ordnung for low-traffic instance-related updates.
The primary instance languages are German and English.