add on_switch_* functions to handle switch events
This commit is contained in:
parent
39cf359df0
commit
e19e59cf27
1 changed files with 12 additions and 2 deletions
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
STATE=0
|
STATE=0
|
||||||
|
|
||||||
|
function check_fn {
|
||||||
|
type $1 &> /dev/null || {
|
||||||
|
echo "$1 is undefined"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
source ~/.etherswitch
|
source ~/.etherswitch
|
||||||
|
|
||||||
if [ -z "$device" ]
|
if [ -z "$device" ]
|
||||||
|
@ -14,6 +21,9 @@ fi
|
||||||
ip link show $device > /dev/null
|
ip link show $device > /dev/null
|
||||||
if [ $? -eq 1 ]; then exit 1; fi
|
if [ $? -eq 1 ]; then exit 1; fi
|
||||||
|
|
||||||
|
check_fn "on_switch_close"
|
||||||
|
check_fn "on_switch_open"
|
||||||
|
|
||||||
while :
|
while :
|
||||||
do
|
do
|
||||||
ip link show $device | grep -q "LOWER_UP"
|
ip link show $device | grep -q "LOWER_UP"
|
||||||
|
@ -22,13 +32,13 @@ do
|
||||||
if [ $STATE -eq 1 ]
|
if [ $STATE -eq 1 ]
|
||||||
then
|
then
|
||||||
STATE=0
|
STATE=0
|
||||||
echo "not connected"
|
on_switch_open
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ $STATE -eq 0 ]
|
if [ $STATE -eq 0 ]
|
||||||
then
|
then
|
||||||
STATE=1
|
STATE=1
|
||||||
echo "connected"
|
on_switch_close
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
sleep 0.3
|
sleep 0.3
|
||||||
|
|
Loading…
Reference in a new issue