Git init
[external/ifupdown.git] / contrib / ensureifup
1 #!/bin/sh
2 # This script is useful to check wether an interface is up and,
3 # if not, it attempts to bring it back. This can be necessary
4 # if your ISP provider causes occasional outages.
5 # Some ISPs are known to termine connections when they reach
6 # 24 hours to "prevent abuse".
7 # Run this script through cron (every 5 minutes? your call)
8 # and ensure that ifstate is located where it is defined below.
9 #
10 # NOTE: This script is just provided as an example. If you want this
11 # feature you might be better off installing ifplugd which provides
12 # similar functionality (but more featureful) out of the box.
13
14 # TODO:
15 # Improve it so it can find out (eg from /etc/network/run/ifstate)
16 # whether an interface was brought down
17 # unexpectedly, or if a clean "ifdown" was issued.
18
19 iface="$1"
20 ifstate=/usr/local/sbin/ifstate
21
22 if [ `$ifstate "$iface"` = DOWN ]
23 then
24     logger -s "Trying to bring $iface back up..."
25     ifdown "$iface"
26     ifup "$iface"
27     [ `$ifstate "$iface"` = UP ] && logger -s "$iface now up again"
28 fi
29
30 exit 0