etherswitch/etherswitch.sh

37 lines
491 B
Bash
Raw Normal View History

2015-03-23 01:36:38 +01:00
#!/bin/env bash
STATE=0
source ~/.etherswitch
2015-03-25 01:23:28 +01:00
if [ -z "$device" ]
2015-03-25 01:21:52 +01:00
then
2015-03-25 01:23:28 +01:00
echo "device is not set"
2015-03-25 01:21:52 +01:00
exit 1
fi
2015-03-25 01:23:28 +01:00
# check if $device is a network device
ip link show $device > /dev/null
2015-03-25 01:21:52 +01:00
if [ $? -eq 1 ]; then exit 1; fi
2015-03-23 01:36:38 +01:00
while :
do
2015-03-25 01:23:28 +01:00
ip link show $device | grep -q "LOWER_UP"
2015-03-23 01:36:38 +01:00
if [ $? -eq 1 ]
then
if [ $STATE -eq 1 ]
then
STATE=0
echo "not connected"
fi
else
if [ $STATE -eq 0 ]
then
STATE=1
echo "connected"
fi
fi
sleep 0.3
done