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="myemail@somewhere.com"
EMAILMESSAGE="IT WORKS"
/bin/mail -s "$SUBJECT" "$EMAIL" "$EMAILMESSAGE"
link|improve this question

67% accept rate
Does that not work? Are you seeing an error, or what? – Zoredache Jan 11 at 18:52
That's SUBJECT, not UBJECT. – Daniel Beck Jan 11 at 19:09
feedback

1 Answer

up vote 2 down vote accepted

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="myemail@somewhere.com"
EMAILMESSAGE="IT WORKS"
echo "$EMAILMESSAGE" | /bin/mail -s "$SUBJECT" "$EMAIL"

Or, for a longer message body:

SUBJECT="FTP Cleanup"
EMAIL="myemail@somewhere.com"
/bin/mail -s "$SUBJECT" "$EMAIL" <<EOF
Message body line 1
Message body line 2
Message body line 3
EOF
link|improve this answer
It works Keith! Thanks also for pointing out that typo. Cheers! – JoyIan Yee-Hernandez Jan 11 at 20:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.