From 9bdc4373e661622a75f8e7a086a1706b31452c1a Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Mon, 22 Sep 2025 00:12:32 +0200 Subject: [PATCH] =?UTF-8?q?usr/local/bin/custom/poe.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/local/bin/custom/poe.sh | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 usr/local/bin/custom/poe.sh diff --git a/usr/local/bin/custom/poe.sh b/usr/local/bin/custom/poe.sh new file mode 100644 index 0000000..17fa02f --- /dev/null +++ b/usr/local/bin/custom/poe.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +USER="admin" +PASS="Expl0rer#2022" +IP_FILE="/usr/local/bin/custom/ips.list" +LOGFILE="/var/log/rpi-$(date '+%Y%m%d%H%M%S').log" + +function disable_poe() { + local switch_ip=$1 + local port=$2 + expect < $" { } +} +send "configure terminal\r" +expect "(config)#" +send "interface $port\r" +expect "(eth-$port)#" +send "no power-over-ethernet\r" +expect "(eth-$port)#" +send "exit\r" +expect "(config)#" +send "exit\r" +expect "#" +send "exit\r" +expect ">" +send "exit\r" +expect "Do you want to log out (y/n)?" { send "y\r" } +expect eof +EOF +} + +function enable_poe() { + local switch_ip=$1 + local port=$2 + expect < $" { } +} +send "configure terminal\r" +expect "(config)#" +send "interface $port\r" +expect "(eth-$port)#" +send "power-over-ethernet\r" +expect "(eth-$port)#" +send "exit\r" +expect "(config)#" +send "exit\r" +expect "#" +send "exit\r" +expect ">" +send "exit\r" +expect "Do you want to log out (y/n)?" { send "y\r" } +expect eof +EOF +} + +echo "" > $LOGFILE +while true; do + echo "--------------------------------------------------------------------" >> $LOGFILE + while IFS=: read -r ip switch port hap; do + ping -c 1 -W 2 $ip &> /dev/null + if [ $? -ne 0 ]; then + echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist nicht erreichbar!" >> $LOGFILE + disable_poe $switch $port + echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch deaktiviert." >> $LOGFILE + sleep 2 + enable_poe $switch $port + echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch aktiviert." >> $LOGFILE + else + echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist erreichbar!" >> $LOGFILE + fi + done < "$IP_FILE" + sleep 300 +done \ No newline at end of file