usr/bin/custom/chromium-monitor aktualisiert
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
|
||||
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
|
||||
get_monitor() {
|
||||
sudo cat /var/lib/dhcp/* | grep -a "option monitor" | tail -1 | \
|
||||
@@ -11,7 +16,7 @@ get_monitor() {
|
||||
|
||||
# Function to get the current window name
|
||||
get_current_window() {
|
||||
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
|
||||
DISPLAY=:0 xdotool getwindowfocus getwindowname
|
||||
}
|
||||
|
||||
# Initialize monitor variable
|
||||
@@ -19,20 +24,20 @@ monitor=""
|
||||
while [ -z "$monitor" ]; do
|
||||
monitor=$(get_monitor)
|
||||
if [ -n "$monitor" ]; then
|
||||
echo "Initial monitor detected: $monitor" >> $LOGFILE # Log initial monitor
|
||||
log "Initial monitor detected: $monitor" # Log initial monitor
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
|
||||
# Main loop to continuously check the current window
|
||||
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
|
||||
# Check for mismatch
|
||||
if [ "$new_current" != "$monitor" ]; then
|
||||
echo "Mismatch detected! Monitor: $monitor, Current: $new_current" >> $LOGFILE
|
||||
echo "Rebooting now." >> $LOGFILE
|
||||
if [ -n "$current_window" ]; then
|
||||
# Check for mismatch using case-insensitive comparison
|
||||
if ! echo "$current_window" | grep -iq "$monitor"; then
|
||||
log "Mismatch detected! Monitor: $monitor, Current: $current_window"
|
||||
log "Rebooting now."
|
||||
sudo reboot
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user