Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-16-2007, 03:18 PM   PM User | #1
pepsi_max2k
New Coder

 
Join Date: Mar 2004
Posts: 96
Thanks: 2
Thanked 0 Times in 0 Posts
pepsi_max2k is an unknown quantity at this point
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..
pepsi_max2k is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:01 AM.


Advertisement
Log in to turn off these ads.