Skip to content

Instantly share code, notes, and snippets.

@danmilleruk
Last active August 24, 2017 22:18
Show Gist options
  • Save danmilleruk/6294151 to your computer and use it in GitHub Desktop.
Save danmilleruk/6294151 to your computer and use it in GitHub Desktop.
Script to check cPanel ports based on an IP address or hostname given as arg1.
#!/bin/bash
# Port Alive Script for Nagios
# Standard cPanel Ports
# Dan Miller <dm@sub6.com>
ADDRESS=$1
TIMEOUT=5
PORTS=(
'2082' # cPanel
'2083' # cPanel SSL
'2086' # WHM
'2087' # WHM SSL
'2095' # Webmail
'2096' # Webmail SSL
);
if [ "$ADDRESS" = "" ]; then
exit 0; # Exit, but ssh! don't tell nagios!
fi
for i in "${PORTS[@]}"
do
:
nc -z -w $TIMEOUT $ADDRESS $i >/dev/null
if [ $? = "1" ]; then
ERROR+="$i "
fi
done
if [ "$ERROR" != "" ]; then
echo "$ERROR NOT REACHABLE"
exit 2
fi
# If we get to here, things are all okay. Clean exit:
echo "ALL PORTS RESPONDING"
exit 0; # good
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment