[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1339
  • Last Modified:

Telnet session in while loop?

I wrote a script that interfaces with some gear and at one point in the script I have to reboot the card. Now I want to create another telnet session that will re-establish the connection once the card comes back up. I want to use a way that tries to connect and if the connection does not get established then I want it to loop back and try again until the connection is back up which would mean the card has finished rebooting.

I tried adding a while loop in this manner but was unsuccessfull.  Anyone have any ideas on how to implement this?

Oh I forgot to mention that I am using Net::Telnet module for the telnet sessions.
0
ZiaTioN
Asked:
ZiaTioN
1 Solution
 
kanduraCommented:
it may be more efficient to just 'ping and sleep' in the while loop:

use Net::Ping;

$p = new Net::Ping;
$up = 0;
$count = 0;
while(!$up and $count<10)
{
  $up = $p->ping( $your_gear_address );
  $count++;
  sleep(2);
}
$p->close();

if($up)
{
  # continue with your telnet session

0
 
ZiaTioNAuthor Commented:
Good idea! Thanks..
0
 
dhruti14Commented:
hello above script what code u wrote to continue your session please help me.. i am able to make telnet session and now i want to ping that session and if session disconnect with any reason i want to reconnect that open session....
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now