Initial version
This commit is contained in:
commit
b14f2b3caa
19
auto_up_script/auto_up_script.sh
Normal file
19
auto_up_script/auto_up_script.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/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
|
28
netlog.sh
Executable file
28
netlog.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
START_DATE=`date`
|
||||||
|
|
||||||
|
mapfile -t ORIGINAL_NETSTATES < <(ip addr | grep " state " | sed -e "s/.* \(.*\):.*state \(.*\) group.*/\1 \2/")
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
sleep 5
|
||||||
|
mapfile -t NETSTATES < <(ip addr | grep " state " | sed -e "s/.* \(.*\):.*state \(.*\) group.*/\1 \2/")
|
||||||
|
|
||||||
|
for (( i=0; i<${#ORIGINAL_NETSTATES[@]}; ++i)); do
|
||||||
|
for (( j=0; j<${#NETSTATES[@]}; ++j)); do
|
||||||
|
OLDSTATE=(`echo ${ORIGINAL_NETSTATES[$i]}`)
|
||||||
|
NEOSTATE=(`echo ${NETSTATES[$j]}`)
|
||||||
|
|
||||||
|
if [ ${OLDSTATE[0]} = ${NEOSTATE[0]} ]; then
|
||||||
|
if [ ${OLDSTATE[1]} = "UP" ]; then
|
||||||
|
if [ ${NEOSTATE[1]} != "UP" ]; then
|
||||||
|
# Alert
|
||||||
|
echo "ALERT"
|
||||||
|
zenity --error --text='Egy hálózati device leállt!'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "Original: ${ORIGINAL_NETSTATES[$i]} Current: ${NETSTATES[$j]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user