netlog/auto_up_script/auto_up_script.sh
2024-10-01 17:53:30 +02:00

20 lines
796 B
Bash

#!/bin/bash
timeout=3 # delay between checks
iface="wlan0" # which network interface to bring up/down
pingip='8.8.8.8' # what to ping
isdown=-1 # indicate whether the interface is up(0) or down(1)
# starts in "unknown" (-1) state
while true; do
if ping -q -c 2 "$pingip"; then # if ping is succeeds bring iface up
if [ "$isdown" -ne 0 ]; then # if not already up
ifconfig "$iface" up && isdown=0
printf ":: iface brought up: %s\n" "$iface"
fi
elif [ "$isdown" -ne 1 ]; then # if ping failed, bring iface down, if not already down
ifconfig "$iface" down && isdown=1
printf ":: iface brought down: %s\n" "$iface"
fi
sleep "$timeout"
done