Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Loop and variable not exactly variable: what's wrong Post 302664663 by bobylapointe on Saturday 30th of June 2012 06:44:07 AM
Old 06-30-2012
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What wrong with the variable definition

i am using the below script and trying to move files in that directory in that pattern to archive. But it doesn;t seem to take the metacharacters. Please sugggest. Code Debug output: (1 Reply)
Discussion started by: dsravan
1 Replies

2. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

3. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

4. Shell Programming and Scripting

Help with variable using loop

Hi I have webserver that I do read data from. Data are stored like this: Huston |1 Portland |2 Hazen |1 Minneapolis |4 Albany |1 Pittsburg |1 Albany |1 Huston |1 Portland|1 Hazen |2 Albany |2 Huston |1 Hazen |1 Script #!/bin/sh user="admin" (1 Reply)
Discussion started by: Jotne
1 Replies

5. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

6. Shell Programming and Scripting

printing variable with variable suffix through loop

I have a group of variables myLINEcnt1 - myLINEcnt10. I'm trying to printout the values using a for loop. I am at the head banging stage since i'm sure it has to be a basic syntax issue that i can't figure out. For myIPgrp in 1 2 3 4 5 6 7 8 9 10; do here i want to output the value of... (4 Replies)
Discussion started by: oly_r
4 Replies

7. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

8. Shell Programming and Scripting

What's wrong after assign it to a variable ?

root@intel_5500_server:/tmp# ID_GUEST="01:00.0" root@intel_5500_server:/tmp# echo $ID_GUEST|sed 's%:%\\:%g' 01\:00.0 root@intel_5500_server:/tmp# ID_GUEST_P=`echo $ID_GUEST|sed 's%:%\\:%g'` root@intel_5500_server:/tmp# echo $ID_GUEST_P 01:00.0 root@intel_5500_server:/tmp# if I assign... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

9. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

10. Shell Programming and Scripting

Storing the value of a single query to a Variable - What am i doing wrong?

I tried the below : #!/bin/ksh testvar=$( sqlplus $user/$pass << EOF set pagesize 0 feedback off verify off heading off echo off; whenever sqlerror exit 1 SELECT 1+1 FROM DUAl; COMMIT; EXIT; EOF) echo "testvar="$testvar The output that I am getting is : > sh example.sh... (3 Replies)
Discussion started by: SriRamKrish
3 Replies
IO::Async::Loop::Poll(3pm)				User Contributed Perl Documentation				IO::Async::Loop::Poll(3pm)

NAME
"IO::Async::Loop::Poll" - use "IO::Async" with "poll(2)" SYNOPSIS
Normally an instance of this class would not be directly constructed by a program. It may however, be useful for runinng IO::Async with an existing program already using an "IO::Poll" object. use IO::Poll; use IO::Async::Loop::Poll; my $poll = IO::Poll->new; my $loop = IO::Async::Loop::Poll->new( poll => $poll ); $loop->add( ... ); while(1) { my $timeout = ... my $ret = $poll->poll( $timeout ); $loop->post_poll; } DESCRIPTION
This subclass of "IO::Async::Loop" uses an "IO::Poll" object to perform read-ready and write-ready tests. To integrate with existing code that uses an "IO::Poll", a "post_poll" can be called immediately after the "poll" method on the contained "IO::Poll" object. The appropriate mask bits are maintained on the "IO::Poll" object when notifiers are added or removed from the set, or when they change their "want_writeready" status. The "post_poll" method inspects the result bits and invokes the "on_read_ready" or "on_write_ready" methods on the notifiers. CONSTRUCTOR
$loop = IO::Async::Loop::Poll->new( %args ) This function returns a new instance of a "IO::Async::Loop::Poll" object. It takes the following named arguments: "poll" The "IO::Poll" object to use for notification. Optional; if a value is not given, a new "IO::Poll" object will be constructed. METHODS
$count = $loop->post_poll( $poll ) This method checks the returned event list from a "IO::Poll::poll" call, and calls any of the notification methods or callbacks that are appropriate. It returns the total number of callbacks that were invoked; that is, the total number of "on_read_ready" and "on_write_ready" callbacks for "watch_io", and "watch_time" event callbacks. $poll Reference to the "IO::Poll" object $count = $loop->loop_once( $timeout ) This method calls the "poll" method on the stored "IO::Poll" object, passing in the value of $timeout, and then runs the "post_poll" method on itself. It returns the total number of callbacks invoked by the "post_poll" method, or "undef" if the underlying "poll" method returned an error. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Loop::Poll(3pm)
All times are GMT -4. The time now is 09:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy