Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a Sub & not waiting for it's completion

Status
Not open for further replies.

saintmike2

Programmer
May 29, 2003
10
US
I have a script that calls a subroutine called "main" that it just basically a just continuous loop that never terminates.
The porblem is that given the struct of the code below, it will read the first line in the file handle run &quot;main&quot; and then stay in main forever without returning back to the original &quot;while (<FH>)&quot; loop. Does anyone know exactly what can be done so that I can just execute &quot;main&quot; but not wait for it's completion?

BEGIN CODE SNIPPET:

while (<FH>)
{
if ($_ =~ /Value0/)
{
$IPAddy = $';
$IPAddy = /\d+\.\d+\.\d+\.\d*/;
$IPAddy = $&;
$Ident = &quot;Value0&quot;;
&main($IPAddy);
sleep(5);
}

if ($_ =~ /Value1/)
{
$IPAddy = $';
$IPAddy = /\d+\.\d+\.\d+\.\d*/;
$IPAddy = $&;
$Ident = &quot;Value1&quot;;
&main($IPAddy);
sleep(5);
}

if ($_ =~ /Value2/)
{
$IPAddy = $';
$IPAddy = /\d+\.\d+\.\d+\.\d*/;
$Ident = &quot;Value2&quot;;
$IPAddy = $&;
&main($IPAddy);
sleep(5);
}
}

/END CODE SNIPPET

Any Ideas?

Mike
 
What does main do, and why does it have to run endlessly
 
The basic premise of the script is to log statistics on several routers. The script takes the IP address of the router and the group the router belongs to from a text file. It hen does a &quot;show interface&quot; on the router at an interval determined by which group it belongs to. For instance, if the router belongs to &quot;Value0&quot; then the script would run &quot;show interface&quot; on the router every 2 minutes. But the script also alerts us if the router generates errors. Thus it must be perpertual in nature.

Mike
 
Look up fork, but you could potentially run quite a few instances doing the same thing

HTH
Paul

Run 3 processes, and as part of their startup, explictly set which group they're in???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top