Solved

Telnet session in while loop?

Posted on 2003-11-18
3
1,161 Views
Last Modified: 2013-01-16
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
Comment
Question by:ZiaTioN
3 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 100 total points
ID: 9774769
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
 
LVL 5

Author Comment

by:ZiaTioN
ID: 9789334
Good idea! Thanks..
0
 

Expert Comment

by:dhruti14
ID: 38784969
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question