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

PERL Script calling a TELNET Session

Status
Not open for further replies.

anon1m0us

Technical User
Nov 21, 2001
3
US
I am trying to TELNET in my PERL script. I am able to issue commands, however, I need to verify that the commands ran succesfully. If not, the Program should abort with an error message. Below is my code, and I tried numerous coding to be able to exit with an error message, but was unsuccesful.

$telnet=new Net::Telnet ( Timeout=>10,Errmode=>'return',Prompt =>'/\$ $/i');

$telnet->open($host) or die $telnet->errmsg;
print "Connected to $host\n";

$telnet->login($ftpuser, $ftppass) or die $telnet->errmsg;
print "Logged in as User: $ftpuser \n";

print "\n\nChecking Remote Server Volume Status\n";
print $telnet->cmd($fverify);

print "\n\nChanging the Remote Server Volume Status to Backup\n";
$telnet->cmd($fbbackup) or die myerr();


print " Verify Volumes Mode\n";

print $telnet->cmd($fverify) or die $telnet->errmsg;
 
I also know about the following commands:
$fh = $obj->input_log;

$fh = $obj->input_log($fh);

$fh = $obj->input_log($filename);

However, either I am using it wrong or it does not do what I need it to do.
 
Try something like ...

@response = $telnet->cmd( $cmd);
pop @response; # drop the first part of the prompt

print @response;
 
i tried "man Net::Telnet". This describes "Errmode=>'die'" errmsg();
Both would seem to do the job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top