From DefCon Projects
Jump to: navigation, search

Manchmal ist es praktisch wenn man bei neuen Kernel-Meldungen informiert wird. Dieses Skript informiert euch per Mail wenn es zu einem neuen Eintrag im dmesg Protokoll gekommen ist.

Skript

#!/bin/bash

# Email configuration
TO_ADDRESS="admin@example.com"
SUBJECT="New dmesg Entry Detected for $(hostname)"
MAIL_CMD="/usr/bin/mail" # Make sure the mail command is installed

# Temporary file to store the last state of dmesg
DMESG_LAST="/tmp/dmesg_last"

# Initialize the dmesg_last file if it doesn't exist
if [ ! -f "$DMESG_LAST" ]; then
    dmesg > "$DMESG_LAST"
    exit 0
fi

# Capture the current state of dmesg
DMESG_CURRENT=$(dmesg)

# Compare with the last state
if ! diff "$DMESG_LAST" <(echo "$DMESG_CURRENT") > /dev/null; then
    # Get the new entries
    NEW_ENTRIES=$(diff "$DMESG_LAST" <(echo "$DMESG_CURRENT") | grep '>' | sed 's/^> //')

    # Send an email with the new entries
    echo "$NEW_ENTRIES" | $MAIL_CMD -s "$SUBJECT" "$TO_ADDRESS"

    # Update the last state
    echo "$DMESG_CURRENT" > "$DMESG_LAST"
fi
Cookies help us deliver our services. By using our services, you agree to our use of cookies.