User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Errors and Email

Tue Nov 12, 2013 10:15 am

I understand that it is possible to have the pi send you an email if there is some error.

I have installed an email client which receives email via Gmail but have no idea where to start to have it send error emails to me. I have searched but the only advice I have found relates to installation and problems.

Any guidance available out there?

User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Re: Errors and Email

Wed Nov 13, 2013 4:24 pm

I am thinking this may work and send a message only if there is an error:

MAILTO=[email protected]
/usr/bin/rsync -avx --delete /media/HDD1/shares/myprofile /media/HDD2/shares/ 2>&1 >/dev/null | tee -a /usr/local/bin/rsync_log

but how to test?

Also if it does work, remove the 'tee -a /usr/local/bin/rsync_log' to no longer have a log as some of the logs are hundreds of lines long?

User avatar
DougieLawson
Posts: 35813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Errors and Email

Wed Nov 13, 2013 6:02 pm

You need sendmail, postfix, procmail or dovecot.

Sendmail is ugly and horrible to configure. You will want to avoid it like the plague. Or try it once, then swear loudly about that ****ing pile of c*** forever.

I'm running postfix on my Ubuntu server and on my RPi. I can relay out to the public Internet using my ISP's email relay.

Once you have postfix (or equivalent) running sending mail becomes trivial using /usr/bin/mail (which can be done from a script) or using the stock standard PHP or python email libraries.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

wimble
Posts: 34
Joined: Tue Feb 05, 2013 9:52 am

Re: Errors and Email

Wed Nov 13, 2013 6:29 pm

Code: Select all

[email protected]
/usr/bin/rsync -avx --delete /media/HDD1/shares/myprofile /media/HDD2/shares/ 2>&1 >/dev/null | tee -a /usr/local/bin/rsync_log
This is a cron configuration. So to utilise it, you would need to edit your crontab by using

Code: Select all

crontab -e
and then inserting that text, with an appropriate schedule. Cron will run your sync command whenever the schedule indicates, and then email the output to the indicated user, using the mail command. If you don't want the output emailed (but just written to the file), then re-write the rsync command without using tee:

Code: Select all

/usr/bin/rsync -avx --delete /media/HDD1/shares/myprofile /media/HDD2/shares/ 2>> /usr/local/bin/rsync_log > /dev/null
If you want to send email (whether from cron, or any other program), you need some version of mail installed. procmail and dovecot don't do this (despite Dougie's mention of them). postfix is the way to go: if all you're doing is sending email from the pi to "somewhere", you should only need a minimal configuration. See http://www.postfix.org/STANDARD_CONFIGU ... ull_client.

User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Re: Errors and Email

Wed Nov 13, 2013 6:54 pm

Thanks both for taking an interest. Perhaps I need to explain what I currently have:

I have Mutt and Citadel installed. I have a script:

Code: Select all

#!/bin/bash

begin=$(date --date="19:00" +%s)
end=$(date --date="21:00" +%s)
now=$(date +%s)

if [ "$begin" -le "$now" -a "$now" -le "$end" ]; then


	echo "/sbin/shutdown -h 25" | sudo at 20:55

else

	begin=$(date --date="3:00" +%s)
	end=$(date --date="6:00" +%s)
	now=$(date +%s)

        if [ "$begin" -le "$now" -a "$now" -le "$end" ]; then

	/usr/bin/rsync -avx --delete /media/HDD1/shares/myprofile /media/HDD2/shares/
	/usr/bin/rsync -avx --delete /media/HDD1/shares/hanprofile /media/HDD2/shares/
	/usr/bin/rsync -avx --delete /media/HDD1/shares/mailwasher /media/HDD2/shares/
	/usr/bin/rsync -avx --delete /media/HDD1/shares/archive /media/HDD2/shares/
	/sbin/shutdown -h 25

else

	echo "don't do rsyncs"

        fi

fi
Sometimes one of the HD's gets 'lost' and that creates an error which I would like to have emailed to me. Otherwise, I don't get to know until the next time AllwaySync tries to update HDD1 when it warns me. I never get to know if the rsync HDD1 to HDD2 has a problem.

Edit: The script is performed at boot and the boot is initiated via a digital timer.

User avatar
DougieLawson
Posts: 35813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Errors and Email

Wed Nov 13, 2013 7:22 pm

wimble wrote: If you want to send email (whether from cron, or any other program), you need some version of mail installed. procmail and dovecot don't do this (despite Dougie's mention of them). postfix is the way to go: if all you're doing is sending email from the pi to "somewhere", you should only need a minimal configuration. See http://www.postfix.org/STANDARD_CONFIGU ... ull_client.
At least you're not suggesting using flaming sendmail. Postfix is the one I'm using because it's not INSANE!

You should be able to add /usr/bin/mail to your script.

Code: Select all

/usr/bin/mail -s "Disk Failed" [email protected]<<EOF
Foobar server [ mounted at $(hostname) ] is running out of disk space!!!
Current allocation ${_SPACE} @ $(date)
EOF
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Re: Errors and Email

Wed Nov 13, 2013 9:03 pm

So can I confirm I can uninstall Mutt and Citadel and install postfix instead?

User avatar
DougieLawson
Posts: 35813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Errors and Email

Wed Nov 13, 2013 9:34 pm

makem2 wrote:So can I confirm I can uninstall Mutt and Citadel and install postfix instead?
Seems like a good idea.
I normally install alpine as a simple mail client.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Re: Errors and Email

Thu Nov 14, 2013 12:07 am

DougieLawson wrote:
makem2 wrote:So can I confirm I can uninstall Mutt and Citadel and install postfix instead?
Seems like a good idea.
I normally install alpine as a simple mail client.
Simple!

I installed Alpine and it took me ages to find out how to start it. Having started it I am faced with humungous quantities of settings. Surely for the simple thing I want I don't have to go through all that?

It's late so I gave up thinking.

User avatar
makem2
Posts: 231
Joined: Tue Jul 02, 2013 9:12 am
Location: Essex
Contact: Website

Re: Errors and Email

Sat Nov 16, 2013 4:29 pm

I have installed exim4 and bsd-mailx. to send error emails only internally.

Code: Select all

 $ mail -s "This is the subject line" pi
hi
EOT
Generates this error:

Code: Select all

 $ /usr/lib/sendmail: Permission denied
"/home/pi/dead.letter" 9/216
. . . message not sent.
A dead.letter message appears in /home/pi

Can anyone suggest how to correct this?

Return to “Raspbian”