usr/bin/custom/chromium-monitor aktualisiert

This commit is contained in:
2024-10-29 14:51:46 +01:00
parent ce9bafa069
commit dcde376e95

View File

@@ -2,6 +2,11 @@
LOGFILE="/var/log/chromium-monitor.log" LOGFILE="/var/log/chromium-monitor.log"
# Function to log messages with timestamps
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOGFILE"
}
# Function to get the monitor value from DHCP # 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 | \
@@ -11,7 +16,7 @@ get_monitor() {
# Function to get the current window name # 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
} }
# Initialize monitor variable # Initialize monitor variable
@@ -19,20 +24,20 @@ monitor=""
while [ -z "$monitor" ]; do while [ -z "$monitor" ]; do
monitor=$(get_monitor) monitor=$(get_monitor)
if [ -n "$monitor" ]; then if [ -n "$monitor" ]; then
echo "Initial monitor detected: $monitor" >> $LOGFILE # Log initial monitor log "Initial monitor detected: $monitor" # Log initial monitor
fi fi
sleep 5 sleep 5
done done
# Main loop to continuously check the current window # Main loop to continuously check the current window
while true; do while true; do
new_current=$(get_current_window | awk '{print $1}') # Get the first word of the current window current_window=$(get_current_window) # Get the current window name
if [ -n "$new_current" ]; then if [ -n "$current_window" ]; then
# Check for mismatch # Check for mismatch using case-insensitive comparison
if [ "$new_current" != "$monitor" ]; then if ! echo "$current_window" | grep -iq "$monitor"; then
echo "Mismatch detected! Monitor: $monitor, Current: $new_current" >> $LOGFILE log "Mismatch detected! Monitor: $monitor, Current: $current_window"
echo "Rebooting now." >> $LOGFILE log "Rebooting now."
sudo reboot sudo reboot
exit 1 exit 1
fi fi