[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Configuration centralizing tool sought

In article <[🔎] 20030201135756.GA30070@fishbowl.madduck.net>,
martin f krafft  <madduck@debian.org> wrote:
>I am in search for a tool that does the following.
>- According to a list of users, the tool goes and finds a particular
>  file relative to the user's home directory. Let's say this file is
>  called foo.rc. If the user list consists of {bob, jane, bill}, then
>  the tool would go and find
>    ~bob/foo.rc
>    ~jane/foo.rc
>    ~bill/foo.rc
>- Before doing anything with the file, the tool then checks directory
>  somewhere under /var for a previous version of the file, e.g.
>    /var/spool/tool/bob/foo.rc
>    /var/spool/tool/jane/foo.rc
>    /var/spool/tool/bill/foo.rc
>    * If a previous file is found, the tool generates a diff and
>      mails it to root.
>- The tool then copies the file from the user's homedirectory to
>  /var/spool/tool/<user>/foo.rc.
>That's it. Conceptually very simple, isn't it? I could write a shell
>script, although perl might be better. But I want to know if there is
>something like that out there already.
>Or if someone more capable on perl than I (i.e. > 0) could whip that
>out of his/her pocket for my perusal. I'll package it and give credit
>in return.

There are not things you should package. It's a one-off that you,
as a capable sysadmin ;), should be able to write in less time as
it took for you to compose this message.

#! /bin/sh
# Usage: tool <backup dir> <config file> <user> [user ..]
shift; shift

for i in $*
	HDIR=`eval echo ~$i`
	if [ -f $HDIR/$RC ]
		if [ ! -d $DIR/$i ]
			mkdir $DIR/$i
		if [ ! -f $DIR/$i/$RC ]
			cp -a $HDIR/$RC $DIR/$i
			echo "** User $i:"
			echo "== Initial copy of $HDIR/$RC to $DIR/$i .. OK"
		elif ! cmp -s $HDIR/$RC $DIR/$i/$RC
			echo "** User $i:"
			echo "== $HDIR/$RC differs from backup $DIR/$i/$RC :"
			diff -u $DIR/$i $HDIR/$RC
			cp -a $HDIR/$RC $DIR/$i
done | mail -s "Tool output" root

Anyone who is capable of getting themselves made President should
on no account be allowed to do the job -- Douglas Adams.

Reply to: