scirpt problem

Discussion in 'Programming/Scripts' started by xrtc, Jun 21, 2006.

  1. xrtc

    xrtc New Member

    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 [email protected]
    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
     
  2. falko

    falko Super Moderator ISPConfig Developer

    What exactly is the problem? Any error messages?
     
  3. Crusader

    Crusader New Member

    This works

    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.

    Code:
    #!/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 [email protected]
    			echo "gnet down"
            fi
    fi
    
    Hope this helps.

    Crusader
     

Share This Page