Solved

This is IBM AIX..Need a script to ping a server

Posted on 2011-03-20
3
431 Views
Last Modified: 2012-05-11
This is in IBM AIX 5.3..Please provide a script which will try to ping or telnet a session to server abcxyz01 on 9704 every couple of mins  and send an e-mail as soon as the port is down..Please let me knoe if you want me to setup the script on the same server or I can do that on other server..
0
Comment
Question by:aixtutorial
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35176663
Hi,

here is a script using "telnet" I once wrote and which several EE askers found useful.
It can test any given port.
Customize PORT, HOST and MAILTO below as desired.

#!/bin/sh
PORT=23
HOST=hostname
MAILTO="aixtutorial@domain.tld"


CHECKFILE=/tmp/sshchk.$$
SLEEPTIME=2

( telnet $HOST $PORT 2>&1 ) > $CHECKFILE &
JOB=$!
   sleep $SLEEPTIME
   kill $JOB 2>/dev/null

if grep -q "Connected to" $CHECKFILE ; then
   :
  else
   mailx -s "Port $PORT on server $HOST is down!" $MAILTO < $CHECKFILE
fi
rm $CHECKFILE 2>/dev/null
exit

wmp
0
 

Author Comment

by:aixtutorial
ID: 35177985
wmp,

I have used the script and executed it..I enetred the worng port just to check if the e-maiis getting trigered..The sendmail daemon is running but havent got any e-mails for this..Please let me know is there anything that I need to modify

Thanks
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 35178718
Well,

in your Q you wrote >> send an e-mail as soon as the port is down << and that's what the script does.

Now here is a version which will send an email in either case (port open or closed).

#!/bin/sh
PORT=23
HOST=hostname
MAILTO="aixtutorial@domain.tld"

CHECKFILE=/tmp/sshchk.$$
SLEEPTIME=2

( telnet $HOST $PORT 2>&1 ) > $CHECKFILE &
JOB=$!
   sleep $SLEEPTIME
   kill $JOB 2>/dev/null

if grep -q "Connected to" $CHECKFILE ; then
   mailx -s "Port $PORT on server $HOST is UP!" $MAILTO < $CHECKFILE
  else
   mailx -s "Port $PORT on server $HOST is DOWN!" $MAILTO < $CHECKFILE
fi
rm $CHECKFILE 2>/dev/null
exit
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question