I am researching how to set up a shell script to run Netstat commands on a UNIX server to scan for open ports. I want each command to run every 5 minutes over a 24 hour period and email me the findings.
Is this possible ?
Sure it's possible.
Though on a UNIX machine, you may want to use something else than netstat
(maybe sockstat
would do better on a FreeBSD server?).
You'll have to do some setup to be able to send mails correctly (sendmail
is already there on a FreeBSD server, but you'll certainly have to enable and configure it a little bit, or install and use another mail software; also, ensure the e-mails your server will be sending are "identified" by mechanisms like spf and dkim to avoid seing them rejected by mail servers).
You can define a cron
job to run the script as regularly as you want, everyday, every minute.
Each of these steps requires some work! I'd proceed slowly, step by step.