Find the answer to your Linux question:
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 28
Hi dylunia, genius! That works perfectly. I have learned a lot today Thanks a bunch, Marinus....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99

    Hi dylunia,

    genius!

    That works perfectly.

    I have learned a lot today

    Thanks a bunch,

    Marinus.

  2. #12
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    I'm very glad it works

    Learning is the best thing about having problems with things
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  3. #13
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    dylunio,

    just one minor problem.

    Code:
    #! /bin/bash
    i="/bin/ping -c 1 www.google.com"
    if $i < 0 ; then
    echo "You have a connection" > /dev/null
    else
    /sbin/ifconfig ath0 up
    /sbin/dhcpcd -t 10 -d ath0
    fi
    I get line 3: 0: No such file or directory.

    What could be wrong?

  4. #14
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    erm, looking at the first line you have a gap between #! and /bin/bash there shouldn't be a gap.

    edit: you may also want to make
    Code:
    /sbin/ifconfig ath0 up
    /sbin/dhcpcd -t 10 -d ath0
    into
    Code:
    /sbin/ifconfig ath0 up && /sbin/dhcpcd -t 10 -d ath0
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  5. #15
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Okay removed it.
    Problem still exists

  6. #16
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    Quote Originally Posted by Marinus
    Okay removed it.
    Problem still exists
    note edit to my above post
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  7. #17
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Same problem.

    Could it be a path error?
    I added the paths to the commands to avoid that but I still get that return.

  8. #18
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,133
    Quote Originally Posted by dylunio
    I've made the following script, and it should work:
    Code:
    #!/bin/bash
    
    i="ping -c 1 www.google.com"
    
    if  $i < 0 ; then
    echo "you have a connection" > /dev/null
    else
    /sbin/dhcpcd -t 10 -d ath0 
    fi
    and if you run that as a cronjob it should be fine.
    The double quotes aren't right for this, that will include the entire content of the command, where you are looking for the return code. Personally I usually compare $? to a preset value, probably "0" here.
    Code:
    ping -c 1 www.google.com;i=$?
    This needs to be set right after the command as exit value is purged when the next command is run.

  9. #19
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    I seemed to have an error with the > (I was redirecting not comparing), so try this:
    Code:
    #!/bin/bash
    
    i="ping -c 1 www.google.com"
    
    if $i<0 ; then
    echo "You have a connection" > /dev/null
    else
    /sbin/ifconfig ath0 up
    /sbin/dhcpcd -t 10 -d ath0
    fi
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  10. #20
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    Quote Originally Posted by bigtomrodney
    Personally I usually compare $? to a preset value, probably "0" here.
    Code:
    ping -c 1 www.google.com;i=$?
    This needs to be set right after the command as exit value is purged when the next command is run.
    The way I use it works for some reason, I don't know why but it does, since I've been testing it. I've been playing with the use of $? for this script and I have yet to get it right.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

Page 2 of 3 FirstFirst 1 2 3 LastLast

Posting Permissions

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