...

View Full Version : Advice needed on a simple loop [solved]



pepsi_max2k
09-16-2007, 03:18 PM
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:


#!/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...


#!/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
}

:confused:


edit: argghh...


#!/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 :)


#!/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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum