Gentoo Archives: gentoo-server

From: Christian Bricart <christian@×××××××.de>
To: gentoo-server@××××××××××××.org
Subject: Re: [gentoo-server] simple shell script
Date: Sat, 02 Apr 2005 21:41:15
Message-Id: 424F1173.5070507@bricart.de
In Reply to: [gentoo-server] simple shell script by Ben Munat
1 Ben Munat schrieb:
2 > Argh. I've been trying to come up with what should be a simple bash
3 > script, but I just can't seem to get it right.
4 >
5 > I'm trying to fix up my cron script that runs sa-learn. I want it to
6 > check to see if there's actually any mails in the directory before
7 > running "sa-learn <my options> <my missed spam dir>" and then "rm <my
8 > missed spam dir>/*".
9
10 Actually, this is not a valid answer to your question - but as in the
11 "Hitchhkers Guide through the Galaxy": "Maybe your question has been all
12 wrong" ;-)
13
14 Why do you want to check if the directioy is empty at all? Just call
15 "sa-learn" either in loop on every file in the directory. If it's emty
16 it's not executed at all.
17 On the other hand, you can call "sa-learn" on an empty directory and
18 you'll get "Learned from 0 messages".
19
20 find /the/path/to/your/directory/ -type f -print0 | xargs -0 \
21 sa-learn <your options>
22 >
23 > I've gone in circles with using the "-e" test ("if [ -e $mydir'/*' ]")
24 > and just command success ("if `ls $mydirwithslashstar`", etc.) and I
25 > can't seem to get it right. What's the simplest way to just test if a
26 > directory is empty?
27
28 that would be something like:
29
30 if [ `ls -l /path/to/directory | wc -l` -eq 0 ]; then
31 ...
32 fi
33
34 (not tested though)
35
36 Christian
37
38 --
39 gentoo-server@g.o mailing list

Replies

Subject Author
Re: [gentoo-server] simple shell script Ben Munat <bent@×××××.com>