FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 03-08-2009, 02:48 AM
Olaf Reitmaier Veracierta
 
Default Bash - Readline in nested whiles?

cat list.txt
a
b

while read r; do echo $r; done < list.txt;
a
b

x=0; while read r; do while [ $x -lt 3 ]; do let x=$x+1; echo $r; done;
done < lista.txt ;

a
a

Why not the output is? Can't be nested while when reading line?
a
a
a
b
b
b

Any comment will be preciated.




--
----------------------------------------------------------------------
"You don't know where your shadow will fall",
Somebody.-

----------------------------------------------------------------------
Ing. Olaf Reitmaier Veracierta <olafrv@gmail.com>
----------------------------------------------------------------------
http://olafrv.googlepages.com (Personal Webpage)
----------------------------------------------------------------------



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-08-2009, 03:08 AM
Mike Bird
 
Default Bash - Readline in nested whiles?

On Sat March 7 2009 19:48:30 Olaf Reitmaier Veracierta wrote:
> cat list.txt
> a
> b
>
> while read r; do echo $r; done < list.txt;
> a
> b
>
> x=0; while read r; do while [ $x -lt 3 ]; do let x=$x+1; echo $r; done;
> done < lista.txt ;
> a
> a
>
> Why not the output is? Can't be nested while when reading line?
> a
> a
> a
> b
> b
> b
>
> Any comment will be preciated.

while read r; do x=0; while [ $x -lt 3 ]; do let x=$x+1; echo $r; done;
done < list.txt

--Mike Bird


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-08-2009, 04:54 AM
Mike Bird
 
Default Bash - Readline in nested whiles?

1) Please don't post HTML to the list.

2) Tell wget to retry (--tries=3) rather than using a loop.

--Mike Bird


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-09-2009, 03:51 AM
Olaf Reitmaier Veracierta
 
Default Bash - Readline in nested whiles?

Olaf Reitmaier Veracierta wrote:

Mike Bird wrote:

On Sat March 7 2009 19:48:30 Olaf Reitmaier Veracierta wrote:


cat list.txt
a
b

while read r; do echo $r; done < list.txt;
a
b

x=0; while read r; do while [ $x -lt 3 ]; do let x=$x+1; echo $r; done;
done < lista.txt ;
a
a

Why not the output is? Can't be nested while when reading line?
a
a
a
b
b
bi

Any comment will be preciated.



while read r; do x=0; while [ $x -lt 3 ]; do let x=$x+1; echo $r; done;
done < list.txt

--Mike Bird




Ok, fine Mike Bird.

But ... the real problem is bellow... and is not resolved with x=0
within nested while...


I mean the tries=0 bellow...

cat minutly.txt
# OCTOPUS_SMS_RF 2009-03-08 12:03:07
2 1
8 2

instance=1
while read line
do
echo $line
if [ ! -z "$line" ] && [ `echo $line | grep
OCTOPUS_SMS_RF | wc -l` -eq 0 ]

then
field1=`echo $line | cut -d" " -f 1`
field2=`echo $line | cut -d" " -f 2`
script="i${instance}m${field1}p${field2}.sh"
rm -f $script
tries=0
while [ ! -f $script ] && [ $tries -lt 3 ]

do
wget
"$url?action=gs&instance=$instance&monitor=$field1 &parameter=$field2" -O
$script

if [ $? -eq 0 ]
then
tries=3
else
let tries=$tries+1
fi
done
fii
done < minutly.txt

The ouput is...

# OCTOPUS_SMS_RF 2009-03-08 12:03:07
2 1
--2009-03-08 00:47:07--
http://localhost/octopus/client.php?action=gs&instance=1&monitor=2&paramete r=1

Resolving localhost... 127.0.0.1, ::1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 322 [text/html]
Saving to: `i1m2p1.sh'

100%[==================>] 322 --.-K/s in 0s


2009-03-08 00:47:07 (24.4 MB/s) - `i1m2p1.sh' saved [322/322]

I can to a better code with | | | | but I don't understand why is
doesn't work with nested whiles...




Hi Mike, thanks for your help.

I solved the problem... zooming on what cause exit the cycle and I found
that there were accidentally some comparison depending on a nonexistent
file ( if [ `cat ... ) because of this the silent fail the while exited.


Here is the new code ... with wget --tries= ...

while read line
do
if [ `echo $line | grep OCTOPUS_SMS_RF | wc -l` -eq 0 ]; then
field1=`echo $line | cut -d" " -f 1`
field2=`echo $line | cut -d" " -f 2`
script="i${instance}m${field1}p${field2}.sh"
rm -f $script
wget --tries=3
"$url?action=gs&instance=$instance&monitor=$field1 &parameter=$field2" -O
$script
if [ ! -e $script ] || [ `cat ${script} | grep OCTOPUS_SMS_RF | wc
-l` -eq 2 ]; then

echo "CLIENT: Error can't wget ${script}."
mail -s "OCTOPUS [ERROR] - $HOSTNAME - wget ${script}"
$OCTOPUS_MAIL < ${script}

fi
fi
done < ${frequency}.txt

Regards.

--
----------------------------------------------------------------------
"You don't know where your shadow will fall",
Somebody.-
----------------------------------------------------------------------
Ing. Olaf Reitmaier Veracierta <olafrv@gmail.com>
----------------------------------------------------------------------
http://olafrv.googlepages.com (Personal Webpage)
----------------------------------------------------------------------


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 06:45 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org