Skip to content

Instantly share code, notes, and snippets.

@flashvoid
Created March 17, 2017 03:29
Show Gist options
  • Save flashvoid/fbdad915d1cb839143a89506d7b3054d to your computer and use it in GitHub Desktop.
Save flashvoid/fbdad915d1cb839143a89506d7b3054d to your computer and use it in GitHub Desktop.
monitor dmesg
#!/bin/bash
period=$1
shift
pattern=$@
last_timestamp=
while :; do
line=$(dmesg | grep "$pattern" | tail -n 1)
timestamp=$(echo $line | cut -d" " -f1 | sed 's/[]\[]//g')
if [[ $timestamp != $last_timestamp ]]; then
echo "Found new occurance of pattern with timestamp $timestamp"
last_timestamp=$timestamp
fi
sleep $period
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment