View Full Version : scirpt problem
xrtc
21st June 2006, 17:33
What i do wrong???
#!/bin/bash
PROXY=`ping 192.168.1.1 -c 1 | grep 100`
if [ ! "$PROXY" ]
then
{
if [ $chk=1 ]
then
{
echo OK
chk=1
}
else
if [ $chk=0 ]
then
{
echo "gnet still down"
}
else
echo "gnet down" | sendmail xrtc@megabyte.gr
echo "gnet down"
fi
fi
}
else exit
fi
also in rc.local i have chk=1
i want to send me mail if the proxy ip is not respoding... 1 mail only
this scprit will run as cronjob every 5 minutes
Thanks in advance
XRtC
falko
22nd June 2006, 16:03
What exactly is the problem? Any error messages?
Crusader
23rd June 2006, 17:19
What i do wrong???
#!/bin/bash
PROXY=`ping 192.168.1.1 -c 1 | grep 100`
if [ ! "$PROXY" ]
then
{
if [ $chk=1 ]
then
{
echo OK
chk=1
}
else
if [ $chk=0 ]
then
{
echo "gnet still down"
}
else
echo "gnet down" | sendmail xrtc@megabyte.gr
echo "gnet down"
fi
fi
}
else exit
fi
also in rc.local i have chk=1
i want to send me mail if the proxy ip is not respoding... 1 mail only
this scprit will run as cronjob every 5 minutes
Thanks in advance
XRtC
Firstly, If you structure your code a little more, then you will be able to see where things aren't quite right.
My example should give you the idea of indenting your code blocks. My example, provides you with a simple IP address check. I am not sure if this is what you want, but it does work. The script could be optimised, but I have made it simple for you to see exactly whats going on.
#!/bin/bash
IPADDRESS='192.168.1.1'
PROXY=`ping $IPADDRESS -c 1`
PROXY1=`ping $IPADDRESS -c 1 | grep 1\ received`
echo "$PROXY"
echo "$PROXY1"
if [ "$PROXY" ]; then
if [ "$PROXY1" ]; then
echo "OK"
else
echo "gnet down" | sendmail -t xrtc@megabyte.gr
echo "gnet down"
fi
fi
Hope this helps.
Crusader
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.