user3002166
user3002166

Reputation: 730

Formatting emails from crontab with ssmtp

I've seen a number of examples on how to setup ssmtp but can't seem to find clear answers how to configure crontab to send data to an email. What I want to accomplish is a crontab config that will send emails with system stats

I've installed and configured ssmtp correctly since I can send emails by doing for example printf "Subject:Test\n\rthis is a test\n\r" |ssmtp [email protected]" and it works exactly as intended. However doing the exact same thing from cron results in command being treated as a string to mail. All backquotes are ignored.

Here I set it to every minute:

MAILTO="[email protected]"
* * * * * bash -c 'printf "Subject:Test\n\rthis is (`date`) a test\n\r" | ssmtp [email protected]'

And Receive:

SUBJECT:
Cron <user@host> printf "Subject:Test\n\rthis is (`date`) a test\n\r" |/usr/bin/ssmtp [email protected]` 
CONTENT:
bash: ssmtp: command not found

where user@host is my local user and pc host and [email protected] is the actual email that should be used to send data. I tried providing full path /user/bin/ssmtp instead of just ssmtp to no avail

Disclaimer: This is a reduced example, there's more data that I want to mail to my monitoring email (A gmail account)

UPDATE

I had to change form /usr/bin/ssmtp to /usr/sbin/sftmp which shows my problem is somewhat different than I initially thought. The emails are sent correctly, but at the same time crontab is sending the old "email" with command as string in subject. I removed all MAILTO= sections from my crontab, but while I can still send my correct emails, I still have CRON commands (not sure how to better phrase it) written out into my e-mail.

So to sum up - I'm getting two emails per crontab task, one being an actual email, and the other being delivery failure with atempt to mail username@hostname from [email protected]

Upvotes: 1

Views: 433

Answers (0)

Related Questions