I seem to be struggling with what I assume will be quite an elementary task for all but the newest of Linux users (me). Hopefully someone can point out any command misuse and in the process I'll gain a better understanding than I've achieved through google searching.
I'm trying to perform a conditional command if files are found below a specified directory:
The syslog and mail.log always show "...No file(s) to delete..." even when spam is present.
Please offer your advice. Bonus cookies if the logger can record how many files were removed. Thanks!
I'm trying to perform a conditional command if files are found below a specified directory:
Code:
server:~# find /var/lib/amavis/virusmails/ -type f
/var/lib/amavis/virusmails/H/spam-H3pxixtQxEy9.gz
server:~# cat badmailpurge
#!/bin/bash
# Find and remove all 'bad' mail files (banned-* / spam-* / virus-*) from the amavis quarantine.
# Record a conditional log message.
badmaildir=/var/lib/amavis/virusmails/
if [ -f 'find $badmaildir -type f' ]; then
# find $badmaildir -type f -exec rm {} \; // will uncomment when message logging is sorted. redundant repetition of previous find command?
logger -i -p mail.info "badmailpurge: Found and removed file(s) from $badmaildir."
else
logger -i -p mail.info "badmailpurge: No file(s) to delete."
fi
server:~#
The syslog and mail.log always show "...No file(s) to delete..." even when spam is present.
Please offer your advice. Bonus cookies if the logger can record how many files were removed. Thanks!