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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retry Connection with Net::Telnet

Status
Not open for further replies.

sthames

Technical User
Apr 2, 2004
9
0
0
US
I have a small script that telnets to a device and reads the values that the device spits out. Sometimes it looses the telnet connection maybe from a power outage, someone playing with the cables, or just sometimes dies. I was trying to figure out how to keep it from dieing and instead keep retrying to connect so that I can continue to read the data. I appreciate the Help!! Below is my script:

use Net::Telnet;
use Win32::ODBC;

$telnet = new Net::Telnet ( Timeout=>86400,
Binmode=>0,
Port=>1000);
$telnet ->open('10.0.0.5');
$noend = 5;
do
{
$database = new Win32::ODBC("Stuff");
($i)=$telnet->waitfor('/\n/');
($i1)=$telnet->waitfor('/\n/');
($i2)=$telnet->waitfor('/\n/');
($i3)=$telnet->waitfor('/\n/');
($i4)=$telnet->waitfor('/\n/');
($i5)=$telnet->waitfor('/\n/');
$i = substr($i,1);
$i1 = substr($i1,1,-3);
$i2 = substr($i2,1,-3);
$i3 = substr($i3,1,-1);
$i4 = substr($i4,1,-3);
$i5 = substr($i5,1,-5);
$database->Sql("Insert INTO TheData (Count,UserID,MyTime,Usage,Total) VALUES ('$i1','$i2','$i3','$i4','$i5')");
close(DATA);
$database->Close();
} while $noend < 100;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top