Find the answer to your Linux question:
Page 3 of 3 FirstFirst 1 2 3
Results 21 to 28 of 28
UPDATED I have made this test script: Code: #!/bin/bash i="/bin/ping -c 1 www.google.com" if $i<0 ; then echo "Connection" > /dev/null else echo "No connection" fi This always results in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #21
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99

    UPDATED

    I have made this test script:

    Code:
    #!/bin/bash
    i="/bin/ping -c 1 www.google.com"
    if $i<0 ; then
    echo "Connection" > /dev/null
    else
    echo "No connection"
    fi
    This always results in

    ... line 3: 0: No such file or directory
    No connection

  2. #22
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    Quote Originally Posted by Marinus
    I have made this test script:

    Code:
    #!/bin/bash
    i="/bin/ping -c 1 www.google.com"
    if $i < 0 ; then
    echo "Connection" > /dev/null
    else
    echo "No connection"
    fi
    This always results in

    PING www.l.google.com (64.233.187.99) 56(84) bytes of data.
    64 bytes ...
    1 packets transmitted, 1 received .....
    test.sh line 3: 0: command not found
    I see the reason your getting that error...it's line gaps which have changed the meaning of things, it should read $i<0 not $i < 0
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  3. #23
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    ... line 3: 0: No such file or directory
    No connection

    Without the spaces I get the above result, even when manual /bin/ping is ok
    Is 0 the default exit value when ping results in good packet transmission?
    And there's still the file not found error...

  4. #24
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    This is realy weird, I have no problems with this script testing my connection on this computer

    erm, looking at the code, it maybe that I'd used the wrong <> bracket. I've just tested the following code, and it seems to work with the internet switched on and off:
    Code:
    #!/bin/bash
    
    i="ping -c 1 www.google.com"
    
    if $i>0 ; then
    echo "You have a connection" > /dev/null
    else
    echo "no connetion"
    /sbin/ifconfig ath0 up
    /sbin/dhcpcd -t 10 -d ath0
    fi
    maybe it'd be an idea to copy/paste this directly.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  5. #25
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    The >0 instead of <0 does the whole trick.

    Thanks again.

    Marinus.

  6. #26
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Quote Originally Posted by dylunio
    I seemed to have an error with the > (I was redirecting not comparing)
    Ah I see, I thought you were comparing it to the value zero.

  7. #27
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    One more question guys.

    How can I direct the mail that cron generates to /dev/null?

    cmd >> /dev/null

    but where do I place this line?

  8. #28
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    Quote Originally Posted by bigtomrodney
    Quote Originally Posted by dylunio
    I seemed to have an error with the > (I was redirecting not comparing)
    Ah I see, I thought you were comparing it to the value zero.
    I was, and still am, but in the first script I had
    Code:
    foo > 0
    aka, foo was redirected to file 0, while I wanted
    Code:
    foo>0
    foo to be more than 0, which seems to have got things working (don't know how though).

    As for redirecting things to /dev/null put > /dev/null after the lines that generage output (this still mails you if there is an error, if you don't want any errors either use &> /dev/null so
    Code:
    echo "no connection" > /dev/null
    /sbin/ifconfig ath0 up > /dev/null
    /sbin/dhcpcd -t 10 -d ath0 > /dev/null
    should do the trick, since cron ony mails if there is an output, and this way one removes the sdout to /dev/null.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

Page 3 of 3 FirstFirst 1 2 3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •