Refactor A72_alarm_getter.sh script for improved readability and reliability

- Removed unnecessary variable interpolation in the 'echo' statement.
- Changed the path for 'atq' and 'atrm' commands to use the full path.
- Updated the 'ping' command to use the full path for better compatibility.
- Added comments and improved formatting for better script understanding.
This commit is contained in:
Ratatoskr 2023-12-07 13:17:18 +01:00
parent 63720dafea
commit a0dbcefb1c
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

View File

@ -8,17 +8,18 @@
# dann das Einschalten der Lichter. # dann das Einschalten der Lichter.
# mit dem "at" Befehl. # mit dem "at" Befehl.
echo "Ausgeführt um: $date" echo "Ausgeführt um: "
date
# Überprüfen, ob alte "at"-Aufträge abgelaufen sind und sie löschen # Überprüfen, ob alte "at"-Aufträge abgelaufen sind und sie löschen
delete_expired_at_jobs() { delete_expired_at_jobs() {
current_time=$(date +"%Y-%m-%d %H:%M:%S") current_time=$(date +"%Y-%m-%d %H:%M:%S")
old_jobs=$(atq | awk -v current_time="$current_time" '$3 < current_time { print $1 }') old_jobs=$(/usr/bin/atq | awk -v current_time="$current_time" '$3 < current_time { print $1 }')
if [ -n "$old_jobs" ]; then if [ -n "$old_jobs" ]; then
echo "Lösche überholte 'at'-Jobs:" echo "Lösche überholte 'at'-Jobs:"
for job_id in $old_jobs; do for job_id in $old_jobs; do
atrm "$job_id" /usr/bin/atrm "$job_id"
echo "Gelöscht: $job_id" echo "Gelöscht: $job_id"
done done
else else
@ -45,7 +46,7 @@ weckzeit_datei="/root/iobroker_scripts/generel/.weckzeiten.txt"
# Überprüfen, ob das Ziel über Ping erreichbar ist # Überprüfen, ob das Ziel über Ping erreichbar ist
function is_target_reachable() { function is_target_reachable() {
echo "teste ping $A72_ip" echo "teste ping $A72_ip"
local ping_output=$(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