commit b14f2b3caa464896490637cda94525415ff90de0 Author: Richard Thier Date: Tue Oct 1 17:53:30 2024 +0200 Initial version diff --git a/auto_up_script/auto_up_script.sh b/auto_up_script/auto_up_script.sh new file mode 100644 index 0000000..04a99f4 --- /dev/null +++ b/auto_up_script/auto_up_script.sh @@ -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 diff --git a/netlog.sh b/netlog.sh new file mode 100755 index 0000000..485727f --- /dev/null +++ b/netlog.sh @@ -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