Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have ports open on a Mac for specific services. Is there a way to have the OS report through e-mail (Smtp) once a connection is established to one of the ports of interest?

share|improve this question
up vote 0 down vote accepted

The simplest solution - to use crontab. Create a file similar to the following:

while [ $t -gt 0 ]; do
ports="$(netstat -n | grep "ESTABLISHED" | awk '{print $4}' | grep -E '.*\.(80|5500|and other interested ports)$')"
if [ "$ports" ];
then t=0; echo $ports | mail -s "subject"
sleep 3

Save it as and make it executable: chmod +x /path/to/ Create in your user directory .crontab file:

*/20 * * * * /path/to/

Checking will be executed every 3 seconds, but the difference in time between the notifications will not be less than 20 minutes, so as not to make it into a spam. You can change these numbers to other, what right for you. And finally - you need to specify the crontab daemon to file: crontab ~/.crontab

share|improve this answer
Thanks, perhaps I will try to accomplish this with CronniX – orlando lopez May 10 '12 at 22:36

Your Answer


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.