Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ Monitoring/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn
        Monitoring
-
AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com


Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com

-
digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

ckport_k93


ckport_k93

Check a network listener port to see if it is running, log an error if it does not accept connections.



#!/usr/bin/ksh93.att
#################################################################
#### !!! Download the latest version of ksh93 to run this script.
#################################################################
function usagemsg_ckport_k93 {
  print -u 2 -- "
Program: ckport_k93

Determine if a network listener is running on a specified
port or service name.

Usage: ${1##*/} [-?] [-vV] [-n nodeName] [-p portNumber]
                           [-t type] [-c class] [-l logFile]
  Where:
    -n nodeName   = Node name of LISTEN'er to test
    -p portNumber = Network port number to test for LISTEN'er
    -t type       = Log Message type: ERROR, WARN (Default:ERROR)
    -c class      = Log Message class: O, S, U (Default:O)
    -l logFile    = Log file name (Default:/var/log/ckport.log)
    -a tcpudp     = IP Protocol type: TCP or UDP (Default:tcp)
    -v            = Verbose Mode
    -V            = Very Verbose Mode

Author: Dana French (dfrench@mtxia.com)
        Copyright 2009 by Dana French: All Rights Reserved

\"AutoContent\" enabled
"
}
################################################################
#### 
#### Description:
#### 
#### Assumptions:
#### 
#### Dependencies:
#### 
#### This function requires a recent version of ksh93.  The version
#### shipped with AIX is INSUFFICIENT to run this script.  Download
#### the latest ksh93 AIX binary from http://www.kornshell.com
#### 
#### If you download the latest ksh93 AIX binary, place it on your
#### system at the location /usr/bin/ksh93.att.  Do not overwrite
#### the existing /usr/bin/ksh93.  Then modify the shebang line
#### to use #!/usr/bin/ksh93.att
#### 
#### Products:
#### 
#### This function records error messages to a default or
#### user specified log file.  The return code from this
#### function can be used to indicate success or failure to
#### resolve the user specified hostname.
#### 
#### Configured Usage:
#### 
#### This function may be executed from the command line or
#### included in a script function library.
#### 
#### Details:
#### 
################################################################
function ckport_k93 {
  typeset VERSION="1.0"
  typeset TRUE="0"
  typeset FALSE="1"
  typeset VERBOSE="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset PORTNUM=""
  typeset NODENAME=""
  typeset TORF=""
  typeset -l UORT="tcp"
  typeset DATETIME=$( date +"%m/%d/%Y %H:%M:%S" )
  typeset SYSTEM="$( hostname )"
  typeset TYPE="${TYPE:-ERROR}"
  typeset CLASS="${CLASS:-O}"
  typeset SOURCE
  typeset DESCRIPTION
  typeset MSG
  typeset LOGFILE="/var/log/ckport.log"

  while getopts ":vVp#n:t:c:l:a:" OPTION
  do
    case "${OPTION}" in
        'p') PORTNUM="${OPTARG}";;
        'n') NODENAME="${OPTARG}";;
        't') TYPE="${OPTARG}";;
        'c') CLASS="${OPTARG}";;
        'l') LOGFILE="${OPTARG}";;
        'a') UORT="${OPTARG}";;
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
      [?:#]) usagemsg_ckport_k93 "${0}" && return 1 ;;
    esac
  done
 
  shift $(( ${OPTIND} - 1 ))

  (( VERYVERB == TRUE )) && set -x
  (( VERBOSE == TRUE )) && print -u 2 -- "# Version................................: ${VERSION}"

################################################################

  trap "usagemsg_ckport_k93 ${0}" EXIT

  if [[ "_${NODENAME}" == "_" ]] || [[ "_${PORTNUM}" == "_" ]]
  then
    (( VERBOSE == TRUE )) && print -u 2 -- "# ERROR: Both the port number and node name must be specified"
    return 1
  fi 

  if ! [[ "_${TYPE}" == _@(ERROR|WARN) ]]
  then
    (( VERBOSE == TRUE )) && print -u 2 -- "# ERROR: Invalid log message type"
    return 1
  fi 

  if ! [[ "_${CLASS}" == _@(O|S|U) ]]
  then
    (( VERBOSE == TRUE )) && print -u 2 -- "# ERROR: Invalid log message class"
    return 1
  fi 

  if ! [[ -d "${LOGFILE%/*}" ]]
  then
    (( VERBOSE == TRUE )) && print -u 2 -- "# ERROR: Invalid log file directory: ${LOGFILE%/*}"
    return 1
  fi 

  if ! [[ "_${UORT}" == _@(tcp|udp) ]]
  then
    (( VERBOSE == TRUE )) && print -u 2 -- "# ERROR: Invalid IP protocol type"
    return 1
  fi 

  trap "-" EXIT

################################################################

#### 
#### If verbose mode was specified by the user on the command
#### line, output the configuration information to the
#### standard error stream STDERR.

  [[ "_${PORTNUM}" == "_" ]] && TORF="Not Specified" || TORF="${PORTNUM}"
  (( VERBOSE == TRUE )) && print -u 2 -- "# Network Port Number....................: ${TORF}"

  [[ "_${NODENAME}" == "_" ]] && TORF="Not Specified" || TORF="${NODENAME}"
  (( VERBOSE == TRUE )) && print -u 2 -- "# Network Service Name...................: ${TORF}"

  (( VERBOSE == TRUE )) && print -u 2 -- "# Network Service Name...................: ${TORF}"
  (( VERBOSE == TRUE )) && print -u 2 -- "# Log message type.......................: ${TYPE}"
  (( VERBOSE == TRUE )) && print -u 2 -- "# Log message class......................: ${CLASS}"
  (( VERBOSE == TRUE )) && print -u 2 -- "# IP protocol typeLog message class......: ${UORT}"

################################################################

  SOURCE="${NODENAME}"
  DESCRIPTION="Port test failed for ${NODENAME}:${PORTNUM}. Node is not LISTENing"
  MSG="${DATETIME} ${SYSTEM} ${SOURCE} ${TYPE} ${CLASS} ${DESCRIPTION}"

  if ( exec 3>/dev/${UORT}/${NODENAME}/${PORTNUM} )
  then
    (( VERBOSE == TRUE )) && print -- "# ${NODENAME}:${PORTNUM} is LISTENing"
    return 0
  else
    (( VERBOSE == TRUE )) && print -- "# ${NODENAME}:${PORTNUM} is not LISTENing"
    print -- "${MSG}" >> "${LOGFILE}"
    return 4
  fi
  exec 3>&-

  return 5
}

################################################################

ckport_k93 "${@}"

-
Network Listener
-
 


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com