Improve IP resolution and add retry mechanism
- Modified the IP resolution process to allow for multiple attempts with a specified interval. - Added a retry mechanism to check the IP address multiple times before considering it unsuccessful. - If the target IP cannot be found after the specified number of attempts, an error message is displayed. - Updated the SSH command to run the alarm script in the background.
This commit is contained in:
parent
4761bfea0f
commit
5f7abef59d
49
wecker.sh
49
wecker.sh
@ -42,29 +42,39 @@ set_color() {
|
|||||||
# Die IP-Adresse von Lisas-IPhone holen und Ping-Test durchführen
|
# Die IP-Adresse von Lisas-IPhone holen und Ping-Test durchführen
|
||||||
check_ip() {
|
check_ip() {
|
||||||
mac_address="e4:cd:d1" # Ersetze dies durch die MAC-Adresse
|
mac_address="e4:cd:d1" # Ersetze dies durch die MAC-Adresse
|
||||||
A72_ip=$(arp-scan --localnet | grep "$mac_address" | awk '{print $1}')
|
attempts=20
|
||||||
|
interval=10
|
||||||
|
|
||||||
if [ -z "$A72_ip" ]; then
|
for ((i = 1; i <= $attempts; i++)); do
|
||||||
echo "IP nicht gefunden. Ziel ist nicht erreichbar."
|
A72_ip=$(arp-scan --localnet | grep "$mac_address" | awk '{print $1}')
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Gefundene IP: $A72_ip"
|
if [ -n "$A72_ip" ]; then
|
||||||
|
echo "Gefundene IP: $A72_ip"
|
||||||
|
|
||||||
# Ping-Test durchführen
|
# Ping-Test durchführen
|
||||||
echo "teste ping $A72_ip"
|
echo "teste ping $A72_ip"
|
||||||
local ping_output=$(/bin/ping -q -w 3 -c 3 $A72_ip 2>&1)
|
local ping_output=$(/bin/ping -q -w 3 -c 3 $A72_ip 2>&1)
|
||||||
local ping_exit_code=$?
|
local ping_exit_code=$?
|
||||||
|
|
||||||
echo "$ping_output" # Ausgabe des Ping-Befehls anzeigen
|
echo "$ping_output" # Ausgabe des Ping-Befehls anzeigen
|
||||||
|
|
||||||
if [ $ping_exit_code -eq 0 ] && [[ "$ping_output" == *"3 received"* ]]; then
|
if [ $ping_exit_code -eq 0 ] && [[ "$ping_output" == *"3 received"* ]]; then
|
||||||
echo "Das Ziel ist erreichbar."
|
echo "Das Ziel ist erreichbar."
|
||||||
return 0 # Erfolg: Das Ziel ist erreichbar
|
return 0 # Erfolg: Das Ziel ist erreichbar
|
||||||
else
|
else
|
||||||
echo "Das Ziel ist nicht erreichbar. Exit Code: $ping_exit_code"
|
echo "Das Ziel ist nicht erreichbar. Exit Code: $ping_exit_code"
|
||||||
return 1 # Fehler: Das Ziel ist nicht erreichbar
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $i -lt $attempts ]; then
|
||||||
|
echo "Warte $interval Sekunden, bevor der nächste Versuch gestartet wird."
|
||||||
|
sleep $interval
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Alle Versuche erfolglos
|
||||||
|
echo "Das Ziel konnte nach $attempts Versuchen nicht erreicht werden."
|
||||||
|
return 1 # Fehler: Das Ziel konnte nicht erreicht werden
|
||||||
}
|
}
|
||||||
|
|
||||||
# check_ip -Funktion ausführen.
|
# check_ip -Funktion ausführen.
|
||||||
@ -121,7 +131,6 @@ check_notification() {
|
|||||||
echo $output
|
echo $output
|
||||||
iobroker state set zigbee.0.04cd15fffee03198.state false
|
iobroker state set zigbee.0.04cd15fffee03198.state false
|
||||||
exit
|
exit
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Startwerte für Helligkeit und Farbtemperatur definieren
|
# Startwerte für Helligkeit und Farbtemperatur definieren
|
||||||
@ -170,7 +179,7 @@ check_ip
|
|||||||
echo "$A72_ip"
|
echo "$A72_ip"
|
||||||
|
|
||||||
# Starten des Alarm-Scripts auf dem Handy.
|
# Starten des Alarm-Scripts auf dem Handy.
|
||||||
ssh -i /root/.ssh/A72 root@$A72_ip '/data/scripts/morning-alarm.sh' > /root/morning_alarm.log
|
ssh -i /root/.ssh/A72 root@$A72_ip "/data/scripts/morning-alarm.sh" &
|
||||||
|
|
||||||
# Farben ändern für mehr konzentration
|
# Farben ändern für mehr konzentration
|
||||||
while :; do
|
while :; do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user