Fix Weckzeit Calculation and Refactoring
- Corrected the calculation of the variable 'lightsOn' to ensure the correct time is set for turning on lights. - Refactored the script by combining the IP retrieval and ping test into a single function 'check_ip'. - Improved error handling and added comments for better readability. Author: Michael, Haider Date: 22.12.2023
This commit is contained in:
parent
11ae8bfaf6
commit
3dd4f72a0e
@ -39,21 +39,19 @@ delete_expired_at_jobs() {
|
|||||||
# Verwende die Funktion, um überholte Jobs zu löschen
|
# Verwende die Funktion, um überholte Jobs zu löschen
|
||||||
delete_expired_at_jobs
|
delete_expired_at_jobs
|
||||||
|
|
||||||
# Die IP-Adresse von Lisas-IPhone holen.
|
# 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}')
|
A72_ip=$(arp-scan --localnet | grep "$mac_address" | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ -z "$A72_ip" ]; then
|
||||||
|
echo "IP nicht gefunden. Ziel ist nicht erreichbar."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Gefundene IP: $A72_ip"
|
echo "Gefundene IP: $A72_ip"
|
||||||
}
|
|
||||||
|
|
||||||
# check_ip -Funktion ausführen.
|
# Ping-Test durchführen
|
||||||
check_ip
|
|
||||||
|
|
||||||
# Datei zum Speichern der geplanten Weckzeiten
|
|
||||||
weckzeit_datei="/root/iobroker_scripts/generel/.weckzeiten.txt"
|
|
||||||
|
|
||||||
# Überprüfen, ob das Ziel über Ping erreichbar ist
|
|
||||||
function is_target_reachable() {
|
|
||||||
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=$?
|
||||||
@ -66,12 +64,15 @@ function is_target_reachable() {
|
|||||||
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
|
return 1 # Fehler: Das Ziel ist nicht erreichbar
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Überprüfen, ob das Ziel erreichbar ist
|
# check_ip -Funktion ausführen.
|
||||||
if is_target_reachable; then
|
check_ip || exit 1 # Beende das Skript, wenn das Ziel nicht erreichbar ist
|
||||||
|
|
||||||
|
# Datei zum Speichern der geplanten Weckzeiten
|
||||||
|
weckzeit_datei="/root/iobroker_scripts/generel/.weckzeiten.txt"
|
||||||
|
|
||||||
# Ziel ist erreichbar, Alarmzeit über SSH abrufen
|
# Ziel ist erreichbar, Alarmzeit über SSH abrufen
|
||||||
alarmTime=$(ssh -i /root/.ssh/A72 root@$A72_ip dumpsys alarm | grep -A 6 ":com.urbandroid.sleep.alarmclock.ALARM_ALERT" | grep "type=RTC_WAKEUP origWhen=" | cut -d= -f3 | cut -c1-16 | uniq)
|
alarmTime=$(ssh -i /root/.ssh/A72 root@$A72_ip dumpsys alarm | grep -A 6 ":com.urbandroid.sleep.alarmclock.ALARM_ALERT" | grep "type=RTC_WAKEUP origWhen=" | cut -d= -f3 | cut -c1-16 | uniq)
|
||||||
|
|
||||||
@ -104,7 +105,3 @@ if is_target_reachable; then
|
|||||||
|
|
||||||
rm "$weckzeit_datei"
|
rm "$weckzeit_datei"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Ziel ist nicht erreichbar."
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user