Solved

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

Posted on 2011-03-20
3
436 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

630 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