Refactor Wecker Script for Improved Readability and Functionality
- Combined IP retrieval and ping test into a single function 'check_ip'. - Improved error handling for better script robustness. - Removed unnecessary commented-out code and added comments for clarity. - Ensured consistency in indentation and formatting. Author: Michael, Haider Date: 22.12.2023
This commit is contained in:
parent
3dd4f72a0e
commit
4761bfea0f
28
wecker.sh
28
wecker.sh
@ -39,11 +39,32 @@ set_color() {
|
|||||||
iobroker state set zigbee.0.04cd15fffee03198.color "$color_value"
|
iobroker state set zigbee.0.04cd15fffee03198.color "$color_value"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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"
|
||||||
|
|
||||||
|
# Ping-Test durchführen
|
||||||
|
echo "teste ping $A72_ip"
|
||||||
|
local ping_output=$(/bin/ping -q -w 3 -c 3 $A72_ip 2>&1)
|
||||||
|
local ping_exit_code=$?
|
||||||
|
|
||||||
|
echo "$ping_output" # Ausgabe des Ping-Befehls anzeigen
|
||||||
|
|
||||||
|
if [ $ping_exit_code -eq 0 ] && [[ "$ping_output" == *"3 received"* ]]; then
|
||||||
|
echo "Das Ziel ist erreichbar."
|
||||||
|
return 0 # Erfolg: Das Ziel ist erreichbar
|
||||||
|
else
|
||||||
|
echo "Das Ziel ist nicht erreichbar. Exit Code: $ping_exit_code"
|
||||||
|
return 1 # Fehler: Das Ziel ist nicht erreichbar
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# check_ip -Funktion ausführen.
|
# check_ip -Funktion ausführen.
|
||||||
@ -70,6 +91,7 @@ check_notification() {
|
|||||||
|
|
||||||
for ((i = 1; i <= $max_attempts; i++)); do
|
for ((i = 1; i <= $max_attempts; i++)); do
|
||||||
# Führe den SSH-Befehl innerhalb eines Timeout aus
|
# Führe den SSH-Befehl innerhalb eines Timeout aus
|
||||||
|
check_ip # IP holen
|
||||||
output=$(ssh -i /root/.ssh/A72 root@$A72_ip 'dumpsys activity processes | grep com.urbandroid.sleep')
|
output=$(ssh -i /root/.ssh/A72 root@$A72_ip 'dumpsys activity processes | grep com.urbandroid.sleep')
|
||||||
echo $output
|
echo $output
|
||||||
|
|
||||||
@ -140,13 +162,13 @@ colortemp_step=$(bc <<< "$start_colortemp / $steps")
|
|||||||
set_brightness "$current_brightness"
|
set_brightness "$current_brightness"
|
||||||
set_colortemp "$current_colortemp"
|
set_colortemp "$current_colortemp"
|
||||||
|
|
||||||
sleep 27 # Änderungen alle 30 (27) Sekunden
|
sleep 30 # Änderungen alle 30 Sekunden
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# check_ip -Funktion ausführen.
|
# check_ip -Funktion ausführen.
|
||||||
check_ip
|
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' > /root/morning_alarm.log
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user