Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Advice needed on a simple loop [solved]

    I'll kill myself for not knowing this but... I wanna create a loop based on the outcome of a query (wl assoclist) that just runs code if it's negative (= "") and if not, sleeps then re-runs the loop. so far I have a very simple 1 line command that does the first part:

    Code:
    #!/bin/sh
    
    if [ "`/usr/sbin/wl -i wl0.1 assoclist`" = "" ]; then
    /usr/bin/killall chilli && /usr/sbin/chilli --conf /jffs/chilli.conf;
    fi
    and the only way i can think of doing the second bit is expanding it to about 20 lines with a separate function and increasing a counter. which just sounds too much to be the best way of doing it. any tips?

    thanks.

    edit: oh hangon...

    Code:
    #!/bin/sh
    
    KILLCHILLI=0
    
    while ($KILLCHILLI == 0) {
       if [ "`/usr/sbin/wl -i wl0.1 assoclist`" = "" ]
       then
            /usr/bin/killall chilli && /usr/sbin/chilli --conf /jffs/chilli.conf
            $KILLCHILLI = 1
       else
            sleep 600
       fi
    }



    edit: argghh...

    Code:
    #!/bin/sh
    
    KILLCHILLI=0
    
    while ($KILLCHILLI == 0)
    do
       if [ "`/usr/sbin/wl -i wl0.1 assoclist`" = "" ]; then
          echo "$KILLCHILLI"
          KILLCHILLI=1
          echo "end loop"
       else
          sleep 60
       fi
    done

    /tmp # /tmp/killchilli2
    /tmp/killchilli2: /tmp/killchilli2: 14: 0: not found


    EDIT: took me half a day but finally got there, and i know i should prolly do a do while instead of while do but i'm not spending another 6 hours over it

    Code:
    #!/bin/sh
    
    KILLCHILLI=0
    KILLEND=4
    
    while [ $KILLCHILLI != $KILLEND ]
    do
        if [ "`/usr/sbin/wl -i wl0.1 assoclist`" = "" ]; then
            KILLCHILLI=$KILLEND
            /usr/bin/killall chilli && sleep 5 & /usr/sbin/chilli --conf /jffs/chilli.conf
        else
            KILLCHILLI=`expr $KILLCHILLI + 1`
            if [ $KILLCHILLI == $KILLEND ]; then
                break
            else
                sleep 480
            fi
        fi
    done
    Last edited by pepsi_max2k; 09-16-2007 at 07:43 PM.


 

Posting Permissions

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