|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Loop and variable not exactly variable: what's wrong
Hello guys, This truly is a newbie question. I'm trying to make a loop to execute simultaneous commands indefinitely while using variable. Here is how my mess looks like (this is just an example): Code:
#!/bin/bash IP=`shuf -n 1 IP.txt` # I figured this would be easier to select random lines from a file TIMES=`shuf -n 1 TIMES.txt` while : do ping -c $TIMES $IP & # "&" to execute commands simulatenously, right? ping -c $TIMES $IP & ping -c $TIMES $IP & sleep 1 done expected results: $IP and $TIMES should be different each time, the script should wait for each ping command to be finished (with success or not) to restart this particular ping command. Could somebody explain to me what's wrong here? Thank you very much |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Where is your script "reading" the new IP for the while loop ? (I see not...) I would have expected: Code:
... .. while read IP do . . #or while IP=`command...` do . . Sorry for not showing more attention, Im doing two others things at the same time + a nasty issue at work... OK extra info: I see no update of your variable IP in your loop... So It is quite normal it shows the same... Last edited by vbe; 06-30-2012 at 07:04 AM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
In the stupid mind of mine, I thought that using $IP should execute `shuf -n 1 IP.txt` each time $IP is used...
|
|
#4
|
||||
|
||||
|
So youve got the logic right now ?
![]() |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Yes, the logic, thanks vbe. I've got some reading to do now ![]() ---------- Post updated at 06:40 AM ---------- Previous update was at 06:31 AM ---------- Code:
ping -c `shuf -n 1 TIMES.txt` `shuf -n 1 IP.txt` does the trick ! Now, I need to find a way for the script to execute all commands simultaneously while at the same time waiting for each ping command to be finished to restart this particular command. I'll update my post once I get it to work.
Last edited by vbe; 06-30-2012 at 08:04 AM.. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| printing variable with variable suffix through loop | oly_r | Shell Programming and Scripting | 4 | 06-26-2012 02:00 PM |
| [SHELL: /bin/sh] For loop using variable variable names | Vryali | Shell Programming and Scripting | 2 | 06-06-2012 10:47 AM |
| How to define a variable with variable definition is stored in a variable? | freddy1228 | Shell Programming and Scripting | 1 | 11-12-2009 03:39 AM |
| variable inside variable inside loop headache | hcclnoodles | Shell Programming and Scripting | 6 | 06-18-2009 04:55 PM |
| What wrong with the variable definition | dsravan | Shell Programming and Scripting | 1 | 09-15-2006 10:57 AM |
|
|