I set up an i-bay as a dropoff point for reporting spam. I have a cron job setup to report and revoke the stuff in IsSpam and NotSpam directories...
----------------------------------------------------
if [ -e /home/e-smith/files/ibays/spam/files/IsSpam/* ] ; then
for X in /home/e-smith/files/ibays/spam/files/IsSpam/*.eml
do
cat "$X" | spamassassin --report
rm -f "$X"
done
fi
if [ -e /home/e-smith/files/ibays/spam/files/NotSpam/* ] ; then
for X in /home/e-smith/files/ibays/spam/files/NotSpam/*.eml
do
cat "$X" | spamassassin --revoke
rm -f "$X"
done
fi
----------------------------------------------------
This works great with 1 or 0 emails in the dir. It either sees the existence of the file and does the for loop, or it doesn't see any messages and doesn't do anything. However, with multiple emails in one dir, the if statement reports "too many arguments" due to the wildcard. Using just the for loop without the if statement, I get "No such file or directory" errors when there's nothing in a dir, though it works fine with 1 or more emails. "if [ -s /home/e-smith/files/ibays/spam/files/NotSpam ]" doesn't work either. It apparently returns true if the directory is empty, and runs the for loop, giving the "No such file or directory" error again.
Is there an option for if to test if a directory is not empty? I'd think this should be rather simple, so I'm probably just missing something...