[svlug] Test for network up in a shell script?
Daniel Pittman
daniel at rimspace.net
Wed Dec 1 00:32:03 PST 2010
conover at rahul.net (John Conover) writes:
> Is there a way of testing to see if the network is up and running from a
> shell script?
Not trivially, no. So, you can try to solve this a bunch of ways, none of
which are absolutely reliable or portable.
If your system has Network Manager installed, the nm-cli tool has a bunch of
reporting capabilities - or you can subscribe to the DBus notifications.
Those give you reasonable information[1] for systems with NM installed and
used.
Otherwise, your best option is to troll the output of /sbin/ip (or ifconfig
and route) to see if there are any interesting looking interfaces up and
with a suitable default route installed.
Daniel
Footnotes:
[1] ...and qdbus is a nice way to interact with it from a shell script; that
is part of KDE, I think.
--
✣ Daniel Pittman ✉ daniel at rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
More information about the svlug
mailing list