Ref: Ändert Skript auf bash
This commit is contained in:
parent
aec631deee
commit
3b0ac86e08
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# === IMPORTS ===
|
# === IMPORTS ===
|
||||||
source NetworkCheck.sh
|
source NetworkCheck.sh
|
||||||
@ -13,9 +13,9 @@ WOL_WAIT=10 # Wartezeit nach WOL (Sekunden)
|
|||||||
|
|
||||||
is_reachable() {
|
is_reachable() {
|
||||||
local device_ip="$1"
|
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..."
|
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."
|
log "Gerät $device_ip ist erreichbar."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@ -31,7 +31,7 @@ send_wol() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_wol_installed() {
|
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"
|
log "Fehler: wakeonlan ist nicht installiert! Bitte installiere es mit: sudo apt install wakeonlan"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -42,7 +42,7 @@ wake_device() {
|
|||||||
local device_mac="$1"
|
local device_mac="$1"
|
||||||
local device_ip="$2"
|
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 "Fehler: MAC- und IP-Adresse müssen angegeben werden!"
|
||||||
log "Verwendung: wake_device <MAC-Adresse> <IP-Adresse>"
|
log "Verwendung: wake_device <MAC-Adresse> <IP-Adresse>"
|
||||||
return 1
|
return 1
|
||||||
@ -57,11 +57,11 @@ wake_device() {
|
|||||||
|
|
||||||
check_wol_installed || return 1 # WOL-Tool prüfen, wenn nicht da, Abbruch
|
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..."
|
log "Wake-on-LAN Versuch $attempt/$WOL_RETRIES..."
|
||||||
send_wol "$device_mac"
|
send_wol "$device_mac"
|
||||||
log "Warte $WOL_WAIT Sekunden..."
|
log "Warte $WOL_WAIT Sekunden..."
|
||||||
sleep $WOL_WAIT
|
sleep "$WOL_WAIT"
|
||||||
|
|
||||||
if is_reachable "$device_ip"; then
|
if is_reachable "$device_ip"; then
|
||||||
log "Gerät ist jetzt erreichbar!"
|
log "Gerät ist jetzt erreichbar!"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user