Re: Automated subscribe/from/record setup script help
* Andrei A. Voropaev <avorop@xxxxxxx> [2003-11-13 05:29 -0900]:
> > FILE="${DIR}/cur/"`ls -t "$DIR"/cur/ |head -1`
> > in place of:
> > FILE=`echo "$DIR"/cur/* |sed 's/.\+ //'`
> > then I get the broken pipe messages.
>
> Sure enough. If you have very long listing then 'head' will exit after
> printing first line and then 'ls' shall get 'broken pipe' error since
> nobody reads on the other side.
Ah! That cleared it up. I simply used '-tr' instead of '-t', and
replaced head with tail. No more broken pipes. But wait, there's more:
> For your case the slow down comes from ls itself since it takes very
> long time to list all the files (IMHO). Consider using 'find'. Also bash
> has arrays, so to get first word from listing you may use
FILE=`find "$DIR"/cur/ | tail -1`
Seems to give the best performance (all non 'time' output snipped):
dave[pogo]~> time ./lists.find
real 0m1.041s
user 0m0.610s
sys 0m0.390s
dave[pogo]~> time ./lists.echo
real 0m1.198s
user 0m0.680s
sys 0m0.470s
dave[pogo]~> time ./lists.ls
real 0m1.224s
user 0m0.650s
sys 0m0.550s
Of course, these are not results that I would stake anything except my
personal scripting upon, but they'll do for now. At least until ...
> After all, consider using perl (or some other scripting tool). Perl has
> function readdir that you can call only once to get first available file
> name.
... I have time to study up on perl/python/lisp/etc. I've been meaning
to do so for some time, and have been dabbling in scheme, but it hasn't
stuck so far.
Thanks for the help!
Regards,
--
dave [ please don't CC me ]