#!/usr/bin/perl use strict; use warnings; use diagnostics; use IO::Handle; use Net::Telnet; my ($host, $username, $passwd) = ("localhost", "issac", "YYYYY"); autoflush STDOUT 1; my $t = Net::Telnet->new(); # Log into unix box print localtime().": Connect to $host..."; my $ok = $t->open(Host => $host, Timeout => 20, Errmode => "return"); die ("Cannot connect to $host telnet server") if !$ok; print "OK\n"; print localtime().": Login to $host..."; $ok = $t->login(Name => $username, Password => $passwd, Timeout => 20, Errmode => "return"); die ("Cannot login to $host telnet server") if !$ok; print "OK\n"; # Read from server continually. # Periodically send text to server. while (1) { my $output = $t->get(Timeout => 10, Errmode => "return"); if (defined $output) { # Recieved text from server print localtime().": get() returned definite output=\"$output\"\n"; } elsif ($t->eof()) { # End of file - server has hung up. print localtime().": get() returned EOF\n"; last; } else { # Timeout occured print localtime().": get() returned TIMEOUT\n"; print localtime().": put() sending string\n"; # Send some crap to the server my $ok = $t->put(String => "echo HELLO\n", Timeout => 10, Errmode => "return"); if (!$ok) { if ($t->eof()) { print localtime().": put() returned EOF\n"; last; } else { print localtime().": put() returned TIMEOUT\n"; } } } }