Just trying to work on a script that will alert me when I get an event.. You can see in the first code box area the running feed of events that I am getting on my Linux box in IP Camera log.. However I am trying to get an alert to terminal on event. last part of that first code box is showing that it is running and has been but only data that it has was the last event that happened before I started that was 8hrs ago. So it has been running and should have pulled in the new events that you can see was 2242..
Code: Select all
Mar 4 21:39:44 10.0.0.236 "EventStart"#012{#012 "Code" : "CrossLineDetection",#012 "Index" : 1,#012 "User" : "System"#012}
Mar 4 21:39:47 10.0.0.236 "EventStop"#012{#012 "Code" : "CrossLineDetection",#012 "Index" : 1,#012 "User" : "System"#012}
Mar 4 22:42:06 10.0.0.236 "EventStart"#012{#012 "Code" : "CrossLineDetection",#012 "Index" : 1,#012 "User" : "System"#012}
Mar 4 22:42:08 10.0.0.236 "EventStop"#012{#012 "Code" : "CrossLineDetection",#012 "Index" : 1,#012 "User" : "System"#012}
Mar 4 22:47:14 10.0.0.175 "LogIn"#012{#012 "Address" : "10.0.0.17",#012 "Type" : "DVRIP"#012}
Mar 4 22:47:25 10.0.0.175 "LogOut"#012{#012 "Address" : "10.0.0.17"#012}
^C
revo2maxx@Rmaxxi7:~$ sudo systemctl status camera-alert.service
[sudo] password for revo2maxx:
● camera-alert.service - Camera Alert Notification Service
Loaded: loaded (/etc/systemd/system/camera-alert.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2025-03-04 15:28:39 EST; 8h ago
Main PID: 119793 (camera-alert.sh)
Tasks: 3 (limit: 38197)
Memory: 2.8M
CGroup: /system.slice/camera-alert.service
├─119793 /bin/bash /usr/local/bin/camera-alert.sh
├─119798 tail -F /var/log/ipcamera.log
└─119799 /bin/bash /usr/local/bin/camera-alert.sh
Mar 04 15:28:39 Rmaxxi7 systemd[1]: Started Camera Alert Notification Service.
Mar 04 15:28:39 Rmaxxi7 camera-alert.sh[119824]: Mar 4 15:25:01 10.0.0.236 "EventStart"
Mar 04 15:28:39 Rmaxxi7 camera-alert.sh[119824]: "Code" : "CrossLineDetection",
revo2maxx@Rmaxxi7:~$
Code: Select all
#!/bin/bash
LOG_FILE="/var/log/ipcamera.log"
ALERT_PIPE="/var/run/camera-alert.pipe"
DEBUG_LOG="/var/log/camera-debug.log"
echo "[DEBUG] Script triggered at $(date)" >> /var/log/camera-debug.log
# Create the pipe if it doesn't exist
[ ! -p "$ALERT_PIPE" ] && mkfifo "$ALERT_PIPE"
# Monitor the log file for events
tail -F "$LOG_FILE" | while read line; do
# Clean the log line by replacing #012 with newlines
CLEAN_LINE=$(echo "$line" | sed 's/#012/\n/g')
# Log the raw and cleaned lines for debugging
echo "[DEBUG] Raw line: $line" >> "$DEBUG_LOG"
echo "[DEBUG] Clean line: $CLEAN_LINE" >> "$DEBUG_LOG"
# Check for event types
if echo "$CLEAN_LINE" | grep -E "EventStart|AudioMutation|CrossLineDetection"; then
TIMESTAMP=$(date)
# Log the matched event
echo "[DEBUG] Match found at $TIMESTAMP: $CLEAN_LINE" >> "$DEBUG_LOG"
# Send alert to the pipe and log it
echo "[$TIMESTAMP] Camera Alert: $CLEAN_LINE" > "$ALERT_PIPE"
echo "[$TIMESTAMP] Camera Alert: $CLEAN_LINE" >> /var/log/camera-alerts.log
fi
done
Thank you in advance
Revo2Maxx