#!/bin/sh

# Store the output of 'klog last' for the past N_TO_KEEP boots.
# Rotate rather than pass args to klog so we have control over how
# many are kept -- klog only supports 1-3, where 1 is a synonym for
# last.  Also, prevent a bunch of duplicates from wiping out useful
# data should this script from being run multiple times on a single
# boot: if the data we collect is identical to our most recent sample
# don't do anything.


N_TO_KEEP=2
KLOG_DIR=/var/log
TMPFILE=/tmp/klog_$$.txt.gz

cd $KLOG_DIR

for N in $(seq $N_TO_KEEP -1 1); do
    if [ -e klog_$N.txt.gz ]; then
        mv klog_$N.txt.gz klog_$((N+1)).txt.gz
    fi
done

klog last | gzip -c > klog_1.txt.gz

dmesg -s 100000 | gzip -c > dmesg.txt.gz
