diff --git a/Utility/WakeOnLan.sh b/Utility/WakeOnLan.sh index 010c77b..a4adfb9 100755 --- a/Utility/WakeOnLan.sh +++ b/Utility/WakeOnLan.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # === IMPORTS === source NetworkCheck.sh @@ -13,9 +13,9 @@ WOL_WAIT=10 # Wartezeit nach WOL (Sekunden) is_reachable() { local device_ip="$1" - for i in $(seq 1 $PING_RETRIES); do + for ((i=1; i<=PING_RETRIES; i++)); do log "Teste Erreichbarkeit von $device_ip - Versuch $i/$PING_RETRIES..." - if ping -c 1 -W 2 "$device_ip" >/dev/null 2>&1; then + if ping -c 1 -W 2 "$device_ip" &>/dev/null; then log "Gerät $device_ip ist erreichbar." return 0 fi @@ -31,7 +31,7 @@ send_wol() { } check_wol_installed() { - if ! command -v wakeonlan >/dev/null 2>&1; then + if ! command -v wakeonlan &>/dev/null; then log "Fehler: wakeonlan ist nicht installiert! Bitte installiere es mit: sudo apt install wakeonlan" return 1 fi @@ -42,7 +42,7 @@ wake_device() { local device_mac="$1" local device_ip="$2" - if [ -z "$device_mac" ] || [ -z "$device_ip" ]; then + if [[ -z "$device_mac" || -z "$device_ip" ]]; then log "Fehler: MAC- und IP-Adresse müssen angegeben werden!" log "Verwendung: wake_device " return 1 @@ -57,11 +57,11 @@ wake_device() { check_wol_installed || return 1 # WOL-Tool prüfen, wenn nicht da, Abbruch - for attempt in $(seq 1 $WOL_RETRIES); do + for ((attempt=1; attempt<=WOL_RETRIES; attempt++)); do log "Wake-on-LAN Versuch $attempt/$WOL_RETRIES..." send_wol "$device_mac" log "Warte $WOL_WAIT Sekunden..." - sleep $WOL_WAIT + sleep "$WOL_WAIT" if is_reachable "$device_ip"; then log "Gerät ist jetzt erreichbar!"