[rescue] Speaking of backups, scripting division

Sheldon T. Hall shel at cmhcsys.com
Sun Nov 10 19:39:20 CST 2002


"Tim H." <lists at pellucidar.net> ...

> On Sun, 10 Nov 2002 16:52:55 -0500
> "Sheldon T. Hall" <shel at cmhcsys.com> wrote:
>
>
> > I was rather unclear in my previous reply.  I want to turn the first 5
> > fields into a human-readable, unique date so I can put the resulting
> > line of text on a status report, or put it in the body of an e-mail.
> >
> > Although comments in the crontab are good, and I have plenty of them,
> > they don't give me the ability to determine dynamically the date and
> > time of the next activity of interest.
> >
> > I want to be able to do this ...
> >
> > echo "The next $activity is scheduled for `crontab -l | grep $activity
> > |
> > some_process`"
> >
> > and get something anyone can read and understand, something I can
> > include on the system's status report, or put in the body of an
> > e-mail, or use in other ways that really have nothing to do with
> > crontab.
> >
> > What I lack is the program some_process, and I'm hoping someone here
> > can point me to the standard way of doing that.
>
> The concept is simple enough, but cron accepts enough different ways to
> say stuff that parsing it fully is going to be tough.  for instance:
>
> */5 in the minute field
>
> is the same as
>
> 0,5,10,15,20,25,30,35,40,45,50,55
>
> and days of week and month can be text or numbers IIRC.
>
> The one good thing is all fields are always required, so you can at
> least chop it up prior to parsing with positional variables.
>
> filter the file through sed to remove comments, then chew it up with
> your favorite mangling tool, perl or whatever.

Right.  I was just hoping that someone more clever and experienced than I
had already worked this out, and I wouldn't heve to.

> I personally would probably do the whole thing with PHP, and serve a
> page from the machine with a neat layout of the cron schedule for the
> next 24 hours or whatever. I dopn't like extra administrative email
> piling up.  hmmm, that actually might be a useful project....

I have a little status report script that produces a simple web page.
Nothing too clever, really, except this part...

tmp1=/tmp/last_dump.tmp1.$$
tmp2=/tmp/last_dump.tmp2.$$

> $tmp1
> $tmp2

df -F ufs -k | grep "/" | cut -c10-80 | sort > $tmp1

for fs in `cut -d' ' -f1 $tmp1`
do
    grep $fs /etc/dumpdates | cut -c11-80 >> $tmp2
done

echo "              Dump                           Current"
echo "------------------------------------- -----------------------"
echo "Device   Lvl         Date             %used    Used     Free
Filesystem"
echo
"-------- --- ------------------------ ----- -------- -------- -------------
----"
paste $tmp2 $tmp1 | \
awk '{printf "%s  %s  %s %s %2s %s %s  %4s %8s %8s  %s\n",\
    $1, $2, $3, $4, $5, $6, $7, $12, $10, $11, $NF}
    {sum += $10}
    END {printf "Total in use                                %8s\n",sum}'

rm -f $tmp1
rm -f $tmp2

... and even that's marginal.

So, what I'd like to add to that is a line that shows when the next backup
is scheduled, and I'd like to do it dynamically, by looking at the actual
"live" crontab.

If no one has done it before, I can certainly do it.  I'm used to doing
stuff no one has ever done before.

-Shel



More information about the rescue mailing list