[TAG] question and announcement, sort of...

Ben Okopnik ben at callahans.org
Fri Jul 16 18:24:45 MSD 2004


On Fri, Jul 16, 2004 at 04:08:04AM +0200, Robos wrote:
> On Wed, 14.07.04, Ben Okopnik <ben at callahans.org> wrote:
> 
> > So, more like this, then:
> > 
> > ----- list.txt --------------------------------------------------------
> > foo at bar 7
> > bar at foo 3
> > joe at xyz 22
> > ann at abc 0
> > -----------------------------------------------------------------------
> > 
> > ----- do_it_to_it -----------------------------------------------------
> > #!/bin/bash
> > # Created by Ben Okopnik on Wed Jul 14 00:31:28 EDT 2004
> > 
> > work_dir="/some/where/over/the/rainbow"
> > max=`ls $work_dir|sort -n|tail -1`
> > 
> > while read mail last
> > do
> >         [ "$last" = "" ] && continue
> >         [ "$((last + 1))" -gt "$max" ] || { 
> > 	((last++))
> >         /usr/bin/mail -s "Command-A-Day" $mail < $work_dir/$last
> >         [ "$?" -gt 0 ] && echo "Problem with $mail!" ||\ 
> > 		echo "$last sent to $mail"
> > 	}
> >         list=`echo -e "$list\n$mail $last"`
> > done < $work_dir/list.txt
> > 
> > OLD=$IFS; IFS=; echo $list|sed '/^$/d' > $work_dir/list.txt; IFS=$OLD
> > ------------------------------------------------------------------------
> 
> THIS IS GREAT! Thanks a lot! I'll look into it a little and try to learn
> from the master :)
 
Aw, shucks. 'T weren't nothin. :)

It's one of those "perfect for shell scripting" scenarios, and you laid
it rather clearly (the second time, anyway), so it wasn't that hard.

> > It's a little fragile - if the script somehow manages to die in the middle
> > of the process, the numbers in the file will not be incremented - but
> > that's not a horrible thing.
> 
> I try and make it a little stronger if I can somehow. You know how people
> react when they get something for free and it doesn't work 100%....

The problem is that if you want that tiny bit of fragility to go away,
you need to modify and rewrite the complete listfile _every time_ you
send an email. If you try to just write out the ones you've sent so far,
the fragility issue becomes much worse: in case of interruption, you
lose _every remaining address;_ that rewrite operation needs to be
atomic. As well, "weakest spot" doesn't mean "weak spot": just because a
20-foot-high barbed-wire fence is a foot lower in one spot than in
another, this doesn't make it any easier to climb. :)

Give it a shot if you want to, but watch out for introducing even worse
problems than the one you're trying to fix.


* Ben Okopnik * okopnik.freeshell.org * Editor-in-Chief, Linux Gazette *
-*- See the Linux Gazette in its new home: <http://linuxgazette.net> -*-




More information about the TAG mailing list