Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

email-smtp.sh - ssh script by ActiveXperts Software

email-smtp.sh checks whether an SMTP server is available.

Use email-smtp.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select email-smtp.sh. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


email-smtp.sh script code

#################################################################################
# ActiveXperts Network Monitor - Shell script checks
# © 1999-2015, ActiveXperts Software B.V.
#
# For more information about ActiveXperts Network Monitor and SSH, please
# visit the online ActiveXperts Network Monitor Shell Script Guidelines at:
#   http://www.activexperts.com/support/network-monitor/online/linux/
#################################################################################
# Script
#     email-smtp.sh
# Description
#     Checks if the SMTP server is available
# Declare Parameters:
#     1) host (string) - Host to check
# Usage
#     email-smtp.sh <host>
# Sample
#     email-smtp.sh smtp.activexperts.com
#################################################################################

#!/bin/sh

# Validate number of arguments
if [ $# -ne 1 ] ; then
  echo "UNCERTAIN: Invalid number of arguments  Usage: email-smtp <host>"
  exit 1
fi

#Checks the connection
# Responses will be cut at 30 characters
sleep 1 | nc $1 25 2>&1 | awk -v host=$1 '
  { 
    if ( $1 == "220") 
      printf( "SUCCESS: Response from [" host "]: [%10.30s] DATA:1\n", $0 );
    else
      printf( "ERROR: Failed to connect to [" host "] DATA:0\n", $0 );
  }';