Re: Simple Scripting ? (Is directory empty?)


Subject: Re: Simple Scripting ? (Is directory empty?)
From: Guillaume Marçais (gus@nist.gov)
Date: Mon Dec 13 1999 - 14:07:04 MST


  Try:
        if [ `ls /var/qmail/alias/pppdir/new/ | wc -l` -eq 0 ]
        then
                echo "Directory empty"
        else
                echo "Directory *not* empty"
        fi

  Guillaume.

On Mon, 13 Dec 1999, Adam Price wrote:

>
> The following script is supposed to do the following:
>
> 1. Look at the directory /var/qmail/alias/pppdir/new/
> 2. If it is nonempty, run the maildirsmtp program to empty it
> 3. Otherwise say there was no mail to send.
>
> Instead, the initial test ALWAYS proves true. This results in lots of
> "directory was empty messages. I have tried various flags, (-s, -f,
> -N) none of them work (and from reading the man pages, they shouldn't)
> I know how I could accomplish this using a temporary file, and cat'ing ls
> into it, but that seem like overkill.
>
> How do I ask bash if a directory is empty?
>
>
>
>
> #!/bin/bash
>
> if test -s /var/qmail/alias/pppdir/new/ <<----HERE's the trouble
>
> then
> #outgoing mail exists - flush it
> /usr/local/bin/maildirsmtp ~alias/pppdir alias-ppp- 207.234.184.12
> echo "sending mail"
>
> else
> # #Let us know the file is empty
> echo "No mail to send"
> exit
> fi
>
>
>
>
> --
> adam@oldchildrensbooks.com
>
> One way to get high blood pressure is to go mountain climbing over molehills.
> -- Earl Wilson
>
>



This archive was generated by hypermail 2a24 : Sun Jan 02 2000 - 12:12:58 MST