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 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
add comment

1 Answer

up vote 0 down vote accepted

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

#!/bin/sh
t=1197
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" your_mail@mail.com
fi
sleep 3
t=$((t-3))
done

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

*/20 * * * * /path/to/123.sh

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 d. May 10 '12 at 22:36
add comment

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.