Script to check if ports are listening

If you are concerned about a DSfW service going down and or the port is not accessible, this script will help keep the services up or notify you of a service going down.  The script will check if each DSfW service is listening, then telnet to each port.  If it can not telnet, the script will log which port is not accessable in the /var/opt/novell/xad/log/dsfw_portchk.log.

The script can be ran on PDC or ADC, running Novell DNS or not running Novell DNS.

The script can also e-mail and restart the services if desired.

It will detect if the server has IPv6 enabled so to properly detect the correct port Samba and NetBios is listening on.

The script detects if Novell DNS is configured to start.  Some times on ADC servers DNS is not configured or is not set to run.  The original script would check if Novell DNS was running whether the service was configured to run or not.

To run the script simply make the script executable.  chmod +x  I would suggest placing the script in the /root/bin/ directory unless your organization has designated places for troubleshooting scripts.
If the script is to be used to ensure all services are listening I would suggest configuring a cronjob for the script to run every 10 minutes, no sooner than every 5 minutes so that the services have a chance to stop and restart.

Key configuration

# Set RESTART_DSFW to 1 to reload DSfW services if one or service is not running,
# Set RESTART_DSFW to 0 to leave the services in reported state

# Set LOGTOSYSLOG to 1 to send messages to /var/log/messages via a SYSLOG

#SITE is the variable for populating the alert email.  Use the domain name or any preferred identifier.
SITE=”dsfw.lan Domain”

# Set EMAILSETTING to 1 to send e-mail when DSfW services fail (postix must be working for this option to work)

# $EMAILTO = the recipient of our alert email. Use a space as delimiter for multiple email addresses.

To continuously run the script create a cronjob.  An example of running the script every 10

crontab -e
*/10 * * * * /root/bin/

Other options might be to run the script between specific times of day because of backups.
Example would be to run the script the between 3 am and 11 pm every hour, starting at the third minute of the hour.  To do this add the following to the crontab

03 3-21/01 * * * /root/bin/

Download the script

5 Responses to Script to check if ports are listening