usr/bin/custom/chromium-monitor aktualisiert
This commit is contained in:
@@ -2,51 +2,45 @@
|
|||||||
|
|
||||||
LOGFILE="/var/log/chromium-monitor.log"
|
LOGFILE="/var/log/chromium-monitor.log"
|
||||||
|
|
||||||
|
# Function to get the monitor value from DHCP
|
||||||
get_monitor() {
|
get_monitor() {
|
||||||
sudo cat /var/lib/dhcp/* | grep -a "option monitor" | tail -1 | \
|
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 '{ s = ""; for (i = 3; i <= NF; i++) s = s $i " "; print s}' | \
|
||||||
awk -F '"' '{print $2}'
|
awk -F '"' '{print $2}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get the current window name
|
||||||
get_current_window() {
|
get_current_window() {
|
||||||
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
|
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Initialize monitor variable
|
||||||
monitor=""
|
monitor=""
|
||||||
while [ -z "$monitor" ]; do
|
while [ -z "$monitor" ]; do
|
||||||
monitor=$(get_monitor)
|
monitor=$(get_monitor)
|
||||||
echo "Current monitor: $monitor" >> $LOGFILE # Debug output
|
if [ -n "$monitor" ]; then
|
||||||
if [ -z "$monitor" ]; then
|
echo "Initial monitor detected: $monitor" >> $LOGFILE # Log initial monitor
|
||||||
sleep 5
|
|
||||||
fi
|
fi
|
||||||
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
# Filter the first word from the initial monitor
|
# Main loop to continuously check the current window
|
||||||
initial_monitor_first_word=$(echo "$monitor" | awk '{print $1}')
|
|
||||||
echo "Monitor (first word): $initial_monitor_first_word" >> $LOGFILE # Debug output
|
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
new_monitor=$(get_monitor | awk '{print $1}')
|
new_current=$(get_current_window | awk '{print $1}') # Get the first word of the current window
|
||||||
new_current=$(get_current_window | awk '{print $1}')
|
|
||||||
|
|
||||||
# Log the current state
|
if [ -n "$new_current" ]; then
|
||||||
echo "New monitor (first word): '$new_monitor'" >> $LOGFILE # Debug output
|
# Check for mismatch
|
||||||
echo "New current window (first word): '$new_current'" >> $LOGFILE # Debug output
|
if [ "$new_current" != "$monitor" ]; then
|
||||||
|
echo "Mismatch detected! Monitor: $monitor, Current: $new_current" >> $LOGFILE
|
||||||
if [ -n "$new_monitor" ] && [ -n "$new_current" ]; then
|
echo "Rebooting now." >> $LOGFILE
|
||||||
if [ "$new_monitor" != "$initial_monitor_first_word" ] || [ "$new_current" != "$initial_monitor_first_word" ]; then
|
|
||||||
echo "Mismatch detected. Rebooting now." >> $LOGFILE
|
|
||||||
sudo reboot
|
sudo reboot
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Either monitor or current is not available, skipping check." >> $LOGFILE
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Log the status before sleeping
|
# Sleep for a short duration before the next check
|
||||||
echo "Sleeping for 5 seconds before the next check..." >> $LOGFILE
|
sleep 5
|
||||||
sleep 5s
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Version 1.0:
|
# 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user