Custom Search

Monday, September 17, 2007

Maintenance Scripts

These probably aren't the most professional system maintenance
scripts ever written, but they get the job done. The first one,
logroll.sh, does just what it says. It rolls over my procmail
and getmail logs, saving them with the date appended and starts
a new log like so:

#!/bin/sh
#
# Script to rotate ~/.procmail/.procmail-log and
# ~/.getmail/log every week so they don't start to
# take on huge proportions.
#
cp ~/.procmail/.procmail-log \
~/.procmail/`date +"%Y%m%d"`.procmail-log.txt
#
echo > ~/.procmail/.procmail-log
#
cp ~/.getmail/log ~/.getmail/`date +"%Y%m%d"`.log.txt
echo > ~/.getmail/log

There's a harder way which I tried first, not thinking, where
the log is copied with the date appended, then delete the log,
then recreate with touch, then chmod to 0600. Lot of work and
unnecessary. All you have to do is copy it with the date and
then echo nothing into it like 'echo >'. Still the same file
as before, just nothing in it, starting over fresh.

The next one is for root, to backup changes in /etc and /var/db
without having to do a dump, just using rsync:

#!/bin/sh
#
# Weelky rsync changes in /etc/ & /var/db to /data2/backups
#
/usr/local/bin/rsync -arvvgt /etc/ /data2/backups/etc && \
/usr/local/bin/rsync -arvvgt /var/db/ /data2/backups/db/

The double 'vv' is for very verbose to give lots of info.

The last script's comments make it pretty self explanatory.
Just a way to keep track of what you've installed lately.

#!/bin/sh
#
# Script lists /var/db/pkg & outputs it to a file with
# the date appended. Then it diffs it against the previous
# list from the week before & outputs the differences to a
# separate file with the date appended. Then it takes the
# most recent list wth date appended & copies/overwrites
# the previous weeks listing to be current.
#
cd /data2/backups
ls -al /var/db/pkg > `date +"%Y%m%d"`pkgs.txt
diff pkgs.inst.list.txt `date +"%Y%m%d"`pkgs.txt > \
`date +"%Y%m%d"`chgs.txt

mv pkgs.inst.list.txt `date +"%Y%m%d"`previous.week.pkgs.txt
cp `date +"%Y%m%d"`pkgs.txt pkgs.inst.list.txt

powered by performancing firefox

Labels:

1 Comments:

Blogger . said...

I found your blog after skimming through comments on undeadly. Good stuff man. Your writing is very high quality... I'm adding you to my RSS reader.

-escapenguin

11/14/2007 09:51:00 PM  

Post a Comment

<< Home