Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-20
3
Medium Priority
?
443 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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

670 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