Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"
share|improve this question
    
Does that not work? Are you seeing an error, or what? –  Zoredache Jan 11 '12 at 18:52
    
That's SUBJECT, not UBJECT. –  Daniel Beck Jan 11 '12 at 19:09

1 Answer 1

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
share|improve this answer
    
It works Keith! Thanks also for pointing out that typo. Cheers! –  JoyIan Yee-Hernandez Jan 11 '12 at 20:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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