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:
---------- 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 ----------
#!/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?
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?
#!/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
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
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 ?
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"
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.