Solved [Solved] Run command when new email.

I want to run a command whenever I have received new unread e-mail. I have an LED connected to my computer which I am able to toggle with a simple command. I want the LED to be on whenever I have unread e-mail in my inbox on that computer.

At first I thought that the task would be simple. But after a lot of googling, I am not able to figure out how to check for new e-mail from cron.

There are several biff applications for X or currently logged in users. None of these seem to be able to run in the background and execute a command when there is a new e-mail.

The simple mail application can check for mail with mail -e giving exit code "0" for mail and "1" for none. But it does not seem to have a similar check for new unread e-mail.

The computer is headless, no X.Org.

Any ideas, anyone?
 
Re: Run command when new email.

The most often used utilities for any kind of additional processing of incoming mail are mail/maildrop (the preferred one now) and mail/procmail. You can do just about anything you want in the rules including running external commands.
 
Re: Run command when new email.

Either of those can run a command to turn on an indicator when mail arrives. But then another command needs to be run to turn off the indicator. That could be part of a shell script that runs after the MUA.

Alternatively, see sysutils/flasher (untested).
 
Re: Run command when new email.

Thanks for the great replies!

I chose to go with the first one. I added this to my crontab:
Code:
*/5 * * * *     /home/user/bin/get_tnh -d /dev/ttyU0 -l 0 && /usr/local/bin/nfrm -Q && /home/user/bin/get_tnh -d /dev/ttyU0 -l 1 > /dev/null 2>&1

It turns off the LED, then checks if there is a new e-mail with nfrm and turns the LED on if there is one. Very simple.

Thanks!

(The LED is the LED on a USB temperature and humidity sensor: http://dograt.homelinux.com:8080/produc ... -tnh-sht10)
 
Back
Top