Re: [SLUG] bash woes - my turn

From: Mike Branda (mike@wackyworld.tv)
Date: Thu Aug 04 2005 - 10:30:12 EDT


On Thu, 2005-08-04 at 02:05 -0400, Eben King wrote:

> > I just figured out that if [ -e $logdir/$file1 ] is what's doing it.
> > The idea was to test for the existance of one or both files and run
> > commands accordingly. So it's trying to test the expansion of both
> > files.
> >
> > + '['
> > -e /home/wacky1/cumulativelog/access.log.2005-07-01.gz /home/wacky1/cumulativelog/access.log.2005-08-01.gz ']
> >
> > gotta love that -x flag of bash. Anyway, how do I tell it to care only
> > if a .gz file exists and not expand all of $file1 in the statement?
>
> Well, if you're going to do something like
>
> for file in *.gz ; do
> # stuff
> done
>
> anyhow, then you could put
>
> [[ -e $file ]] || exit
>
> inside it. If there are no *.gz files, the "*" won't be expanded and the
> loop will be run (once) with file="*.gz". Usually that won't exist, so in
> that case it aborts.
>
> The other code I can think of is something like
>
> [[ $(ls -1 *.gz 2> /dev/null | wc -l) -eq 0 ]] && exit 1
>
> before everything. I think checking for the existence of each file takes
> less time than listing and counting them all, but you should do timings if
> it's critical.
>

As of right now it's only been running this way for 3 months (well,
we're in the 3rd). There's only 3 files. 2 gzips and the current
month's access file. Eventually there will probably be up to 2 dozen
(the last 2 years worth of statistics). After that I intend to archive
the files. We'll see how slow it gets then!! :^)

Thanks for all your help Eben. I really appreciate it.

Mike

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:42:01 EDT