75 lines
1.9 KiB
Bash
Executable File
75 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# === IMPORTS ===
|
|
source NetworkCheck.sh
|
|
source Log.sh
|
|
|
|
# === KONFIGURATION ===
|
|
PING_RETRIES=2 # Anzahl der PING-Versuche vor WOL
|
|
WOL_RETRIES=2 # Max. Anzahl der WOL-Versuche
|
|
WOL_WAIT=10 # Wartezeit nach WOL (Sekunden)
|
|
|
|
# === FUNKTIONEN ===
|
|
|
|
is_reachable() {
|
|
local device_ip="$1"
|
|
for i in $(seq 1 $PING_RETRIES); do
|
|
log "Teste Erreichbarkeit von $device_ip - Versuch $i/$PING_RETRIES..."
|
|
if ping -c 1 -W 2 "$device_ip" >/dev/null 2>&1; then
|
|
log "Gerät $device_ip ist erreichbar."
|
|
return 0
|
|
fi
|
|
done
|
|
log "Gerät $device_ip ist NICHT erreichbar."
|
|
return 1
|
|
}
|
|
|
|
send_wol() {
|
|
local device_mac="$1"
|
|
log "Sende Wake-on-LAN Signal an $device_mac..."
|
|
wakeonlan "$device_mac"
|
|
}
|
|
|
|
check_wol_installed() {
|
|
if ! command -v wakeonlan >/dev/null 2>&1; then
|
|
log "Fehler: wakeonlan ist nicht installiert! Bitte installiere es mit: sudo apt install wakeonlan"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
wake_device() {
|
|
local device_mac="$1"
|
|
local device_ip="$2"
|
|
|
|
if [ -z "$device_mac" ] || [ -z "$device_ip" ]; then
|
|
log "Fehler: MAC- und IP-Adresse müssen angegeben werden!"
|
|
log "Verwendung: wake_device <MAC-Adresse> <IP-Adresse>"
|
|
return 1
|
|
fi
|
|
|
|
wait_for_internet_connection
|
|
|
|
if is_reachable "$device_ip"; then
|
|
log "Gerät ist bereits an, kein WOL nötig."
|
|
return 0
|
|
fi
|
|
|
|
check_wol_installed || return 1 # WOL-Tool prüfen, wenn nicht da, Abbruch
|
|
|
|
for attempt in $(seq 1 $WOL_RETRIES); do
|
|
log "Wake-on-LAN Versuch $attempt/$WOL_RETRIES..."
|
|
send_wol "$device_mac"
|
|
log "Warte $WOL_WAIT Sekunden..."
|
|
sleep $WOL_WAIT
|
|
|
|
if is_reachable "$device_ip"; then
|
|
log "Gerät ist jetzt erreichbar!"
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
log "Fehler: Gerät konnte nach $WOL_RETRIES Versuchen nicht erreicht werden."
|
|
return 1
|
|
}
|