2

I have a script that works removing files x days and keep the folders. I'm trying to send an email once its done with the deletion. Any advice? Current script is below:

#!/bin/bash
find /testftp/* -type f -mtime +10 -exec rm {} \;
UBJECT="FTP Cleanup"
EMAIL="[email protected]"
EMAILMESSAGE="IT WORKS"
/bin/mail -s "$SUBJECT" "$EMAIL" "$EMAILMESSAGE"
2
  • Does that not work? Are you seeing an error, or what?
    – Zoredache
    Jan 11, 2012 at 18:52
  • That's SUBJECT, not UBJECT.
    – Daniel Beck
    Jan 11, 2012 at 19:09

1 Answer 1

2

One problem: you misspelled SUBJECT, but the only problem that will cause is that the message will have an empty subject.

The bigger problem is that /bin/mail reads the message body from standard input, not from a command line argument.

Try this:

SUBJECT="FTP Cleanup"
EMAIL="[email protected]"
EMAILMESSAGE="IT WORKS"
echo "$EMAILMESSAGE" | /bin/mail -s "$SUBJECT" "$EMAIL"

Or, for a longer message body:

SUBJECT="FTP Cleanup"
EMAIL="[email protected]"
/bin/mail -s "$SUBJECT" "$EMAIL" <<EOF
Message body line 1
Message body line 2
Message body line 3
EOF
1
  • It works Keith! Thanks also for pointing out that typo. Cheers! Jan 11, 2012 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .