usr/bin/custom/chromium-monitor aktualisiert

This commit is contained in:
2024-10-28 16:59:11 +01:00
parent d012e5193d
commit 73ea27ac67

View File

@@ -2,51 +2,45 @@
LOGFILE="/var/log/chromium-monitor.log"
# Function to get the monitor value from DHCP
get_monitor() {
sudo cat /var/lib/dhcp/* | grep -a "option monitor" | tail -1 | \
awk '{ s = ""; for (i = 3; i <= NF; i++) s = s $i " "; print s}' | \
awk -F '"' '{print $2}'
}
# Function to get the current window name
get_current_window() {
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
}
# Initialize monitor variable
monitor=""
while [ -z "$monitor" ]; do
monitor=$(get_monitor)
echo "Current monitor: $monitor" >> $LOGFILE # Debug output
if [ -z "$monitor" ]; then
sleep 5
if [ -n "$monitor" ]; then
echo "Initial monitor detected: $monitor" >> $LOGFILE # Log initial monitor
fi
sleep 5
done
# Filter the first word from the initial monitor
initial_monitor_first_word=$(echo "$monitor" | awk '{print $1}')
echo "Monitor (first word): $initial_monitor_first_word" >> $LOGFILE # Debug output
# Main loop to continuously check the current window
while true; do
new_monitor=$(get_monitor | awk '{print $1}')
new_current=$(get_current_window | awk '{print $1}')
new_current=$(get_current_window | awk '{print $1}') # Get the first word of the current window
# Log the current state
echo "New monitor (first word): '$new_monitor'" >> $LOGFILE # Debug output
echo "New current window (first word): '$new_current'" >> $LOGFILE # Debug output
if [ -n "$new_monitor" ] && [ -n "$new_current" ]; then
if [ "$new_monitor" != "$initial_monitor_first_word" ] || [ "$new_current" != "$initial_monitor_first_word" ]; then
echo "Mismatch detected. Rebooting now." >> $LOGFILE
if [ -n "$new_current" ]; then
# Check for mismatch
if [ "$new_current" != "$monitor" ]; then
echo "Mismatch detected! Monitor: $monitor, Current: $new_current" >> $LOGFILE
echo "Rebooting now." >> $LOGFILE
sudo reboot
exit 1
fi
else
echo "Either monitor or current is not available, skipping check." >> $LOGFILE
fi
# Log the status before sleeping
echo "Sleeping for 5 seconds before the next check..." >> $LOGFILE
sleep 5s
# Sleep for a short duration before the next check
sleep 5
done
# Version 1.0:
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspbian as custom PXE init script.