Ping trace telnet monitoring script


 
Thread Tools Search this Thread
Operating Systems Solaris Ping trace telnet monitoring script
# 1  
Old 07-16-2011
Ping trace telnet monitoring script

Hello, it is my first post Smilie
I need to implement some monitoring tools in a script, ping telnet traceroute

I found this one to ping, it works,
Code:
#!/bin/sh
for i in `cat /tmp/PingStatus.txt`
do
  ping -c 5 -w 5 -n $i | grep -q "bytes from" && echo "$i is OK"  || opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text="PING  BROKEN on $line"
done

but I would also need to check traceroute and telnet on different ports 80,21,9000... towards different servers,routers. How can I implement it ?

thanks a lot!

Last edited by Scott; 07-17-2011 at 11:55 AM.. Reason: Code tags
# 2  
Old 07-16-2011
Telnet:
Code:
echo "b" | telnet -e "b" $i $port

You might want to consider wrapping some code round it to allow a shorter timeout than the default (something like 2 minutes from memory?).
Rough code to give you the idea:
Code:
timeout=15  #seconds
echo "b" | telnet -e "b" $i $port &
pid=$!
count=0
while /usr/ucb/ps -aux $pid > /dev/null && [ "$count" -lt "$timeout" ]
do
  sleep 1
  count=`expr $count + 1`
done


Last edited by Smiling Dragon; 07-16-2011 at 08:49 AM..
# 3  
Old 07-16-2011
Sorry too difficult to me, need something simple right now Smilie
Code:
ping -c 5 -w 5 -n 192.168.1.1 | grep -q "bytes from" && echo "Gateway , Ping is OK"
traceroute 10.22.1.6 | grep -q "10.22.1.6" && echo "PROXY, Traceroute is OK"
telnet 10.22.1.77 80 | grep -q "Connected" && echo "WEB por is OK"

---------- Post updated at 09:31 AM ---------- Previous update was at 08:55 AM ----------

Can you please give me something to start with? I've been reading some shell script tutorial but I'm even not sure which way to monitor those services (using if, while..)

---------- Post updated at 10:17 AM ---------- Previous update was at 09:31 AM ----------
Code:
#!/bin/bash
WEB="www.google.com"

ping -c 5 -w 5 -n ${WEB} | if [ grep -q "bytes from" ]
then
   echo ${WEB} " is up"
else
   echo ${WEB} " is DOWN"
fi

how can I save the condition if [ grep -q "bytes from" ] in a variable?

Last edited by Scott; 07-17-2011 at 11:56 AM.. Reason: Code tags
# 4  
Old 07-17-2011
Well the telnet one I gave above (the single line) should work as-is:
Code:
echo "b" | telnet -e "b" $i $port

Where $i is you target host/ip and $port is the port number you need to try.

The echo "b" and the -e "b" parts are telling telnet to immediately quit once it gets a connection. This means you can use your above logic with it:
Code:
echo "b" | telnet -e "b" $i $port && echo "${i}:${port} is OK"

For your last question with ping and the if statement, I'm not actually sure what you are trying to do to be honest,but perhaps you want something like this?
Code:
#!/bin/sh
# You don't need bash for something this simple, sh is just fine and works everywhere
WEB="www.google.com"

if ping -c 5 -w 5 -n ${WEB} | grep -q "bytes from"
then
  echo ${WEB} " is up"
else
  echo ${WEB} " is DOWN"
fi

This User Gave Thanks to Smiling Dragon For This Post:
# 5  
Old 07-17-2011
thanks for your reply,

Code:
WEB="www.google.it"
GW="192.168.1.1"
PORT="80"


if ping -c 5 -w 5 -n ${GW} | grep -q "bytes from"
then
  echo ${GW} " is OK"
else
  echo ${GW} " is DOWN"
fi

if telnet -e "b" ${WEB} ${PORT} | grep -q "connected to"
then
  echo ${WEB}:${PORT} " is OK"
else
  echo ${WEB}:${PORT} " is DOWN"
fi

Code:
marmellata@marmellata-desktop:~/testping$ sh test.sh 
192.168.1.1  is OK
..
..
..

it stops on telnet command



Kind regards

-

---------- Post updated at 08:52 AM ---------- Previous update was at 08:43 AM ----------

I've been also trying to implement traceroute command so that if I can reach PROXY I get an answer or if I dont reach PROXY but can rach PROXY1 I get another answer. Doesnt work, how can I do it ?

Code:
PROXY="10.99.4.1"
PROXY1="10.40.4.1"

if traceroute ${PROXY} | grep -q "10.99.4.1"
then
  echo ${PROXY} " is OK"
elif grep -q "10.40.4.1" !"10.99.4.1"
then
  echo ${PROXY} " is DOWN but "${PROXY1} " is UP"


Last edited by Scott; 07-17-2011 at 11:57 AM.. Reason: Please use code tags
# 6  
Old 07-28-2011
Quote:
Originally Posted by marmellata
Code:
WEB="www.google.it"
GW="192.168.1.1"
PORT="80"


if ping -c 5 -w 5 -n ${GW} | grep -q "bytes from"
then
  echo ${GW} " is OK"
else
  echo ${GW} " is DOWN"
fi

if telnet -e "b" ${WEB} ${PORT} | grep -q "connected to"
then
  echo ${WEB}:${PORT} " is OK"
else
  echo ${WEB}:${PORT} " is DOWN"
fi

it stops on telnet command
You've dropped the echo "b" part of the telnet line, it's important as you've set the escape char to b with the -e "b" flag, but you still need to send it to telnet for it to do anything.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

2. Shell Programming and Scripting

ping and telnet timeout

Hello, I need help, I have the following which save in the result file ping and telnet:port test. Basically the script works but I should implement a check on ping and telnet command so that ping has 5 seconds threshold and telnet (more important) 10 seconds. Over that threshold ping and... (0 Replies)
Discussion started by: marmellata
0 Replies

3. UNIX for Dummies Questions & Answers

ping,telnet, traceroute

can you provide the command in solaris8 if I wanted to ping,telnet, traceroute an IP address with a port? thanks (1 Reply)
Discussion started by: lhareigh890
1 Replies

4. AIX

ping OK - telnet refused

Hi, After a crash of our older AIX server it happend as it is in the title: ping is ok, but telnet: What it can be this strange thing? Franci (2 Replies)
Discussion started by: frajer
2 Replies

5. UNIX for Advanced & Expert Users

ping and telnet - HP-UX

Hi all, I am not sure if my problem is specific to HP-UX or not. Hopefully someone can tell me what's wrong. I have a server name server1 10.100.50.10 in the /etc/hosts file and if I do a ping server1, it shows the right IP address. However, if I run telnet server1, it is not using... (4 Replies)
Discussion started by: newbie_01
4 Replies

6. Infrastructure Monitoring

no telnet, ping ok...

We have a Sun Solaris Netra 20 server. Our O&M Server gets Alarm Processor not responding. When Alarm occurs, you can ping the sun server but cannot telnet it. We keep getting Interrupt level not serviced. var/adm/message log is > tail -f messages Apr 12 20:09:56 cama pcisch: PCI-device:... (9 Replies)
Discussion started by: krabu
9 Replies

7. Shell Programming and Scripting

Monitoring script (Ping, MySQL)

Hi guys - Relatively new to shell programming so please bare with me (I bet everyone says that!) I'm faced with a problem: I need a shell script to do the following: Connect to a MySQL database and pull all entrys from the nodes field in a table called 'nodes' These nodes will then be... (1 Reply)
Discussion started by: daveomcgee
1 Replies

8. IP Networking

can ping but can not telnet UNIX

I have one problem and it is giving me hard time I can ping my windows machine root@x1ChXpress:/sbin >ping 192.168.129.66 192.168.129.66 is alive root@x1ChXpress:/sbin >netstat -rn Routing Table: Destination Gateway Flags Ref Use Interface... (3 Replies)
Discussion started by: amon
3 Replies

9. AIX

Ping/Telnet is not happening

Hi All, We are not able to ping to a AIX box...Network is ok..when we give ping from that AIX box..it is giving 0821-067 ping: The socket creation call failed.there is no enough buffer space for the requested socket operation. refresh -s inetd is also giving socket error. Please help to... (1 Reply)
Discussion started by: b_manu78
1 Replies

10. IP Networking

ping and telnet

I can ping other computers in my office. I can telnet other users in my office but i cannot get out of the office network. If i try to go out side of my network it cannot find host. Any ideas? (5 Replies)
Discussion started by: macdonto
5 Replies
Login or Register to Ask a Question