Solved

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

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now