Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

821 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