Subject: Re: save old dmesg outputs
To: None <tech-userlevel@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-userlevel
Date: 07/30/2006 10:55:22
On Sun, 30 Jul 2006, Hubert Feyrer wrote:
> I think /etc/security's backup_and_diff() invoked on every time
> /etc/rc.d/dmesg gets ran (with secibd arument set to "no" to not print
> the diff) sounds pretty easy. The function needs to get migrated to
> rc.subr, though.
My /etc/rc.d/dmesg has been backing up to RCS for several years (using
backup_file from /etc/rc.subr). Last time I mentioned this, people
thought that it was pointless. If that opinion has changed, I'd be
happy to get my patches into a state where they can be committed.
Working but ugly patch appended.
--apb (Alan Barrett)
--- rc.d/dmesg (NetBSD: dmesg,v 1.9 2004/08/13 18:08:03)
+++ rc.d/dmesg 2005-08-08 13:10:58.000000000 +0200
@@ -12,13 +12,49 @@
name="dmesg"
rcvar=$name
dmesg_file="/var/run/dmesg.boot"
+backup_dir="${backup_dir:-/var/backups}"
+#work_dir="${backup_dir}/work"
+work_dir="${backup_dir}/${dmesg_file%/*}"
start_cmd="do_dmesg"
stop_cmd=":"
do_dmesg()
{
+ set -x
+ mkdir -p ${work_dir}
+ BASE=${dmesg_file##*/}
+ CUR=${work_dir}/${BASE}.current
+ BACK=${work_dir}/${BASE}.backup
+ #echo "start"
+ #ls -ld ${dmesg_file} ${CUR} ${CUR},v
+ # Backup the old file left over from the previous boot,
+ # if it was not already backed up.
+ if [ -f ${dmesg_file} ]; then
+ if [ -f $CUR ] && cmp -s ${dmesg_file} $CUR; then
+ : OK
+ else
+ echo "Backing up old ${dmesg_file} from previous boot."
+ backup_file update ${dmesg_file} $CUR $BACK
+ fi
+ fi
+ #echo "saved old"
+ #ls -ld ${dmesg_file} ${CUR} ${CUR},v
+ # Create the new file.
rm -f ${dmesg_file}
( umask 022 ; /sbin/dmesg $rc_flags > ${dmesg_file} )
+ #echo "new"
+ #ls -ld ${dmesg_file} ${CUR} ${CUR},v
+ # Backup the new file, if it has changed.
+ if [ -f $CUR ] && cmp -s ${dmesg_file} $CUR; then
+ : No changes
+ echo "Not backing up unchanged ${dmesg_file}"
+ else
+ #diff -u2 ${CUR} ${dmesg_file}
+ echo "Backing up new ${dmesg_file}"
+ backup_file update ${dmesg_file} $CUR $BACK
+ fi
+ #echo "end"
+ #ls -ld ${dmesg_file} ${CUR} ${CUR},v
}
load_rc_config $name