maderman has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm trying to use Net::Telnet to get the time on a Vax. My code is:
use Net::Telnet; use strict; my($telnet, $timeout, $command, @line); my $name = 'user'; my $passwd = 'password'; my $host = 'host'; $timeout = 900; $telnet = Net::Telnet->new( Prompt => '/prompt\$/', Dump_Log => 'dump.log', Input_Log => 'input.log', Output_Log => "output.log", Host => $host, Timeout => $timeout, ); $telnet->login(Name => $name, Password => $passwd, Prompt => '/prompt\$/' ); @line = $telnet->print('sh time'); $telnet->waitfor('/prompt\$/'); $telnet->print("lo"); #logout $telnet->close;
The returned result is line: 1. From the dump_log (see below), it looks like my command is getting passed, but why am I getting a "1" instead of 1-DEC-2001 01:23:33? It doesn't matter if I put $line = $telnet->print('sh time') - scalar reference, or @line = $telnet->print('sh time') - array reference. I still get a "1". Many thanks.
> 0x00000: 73 68 20 74 69 6d 65 0d 0a sh time.. < 0x00000: 73 68 20 74 69 6d 65 0d 0a sh time.. < 0x00000: 0d 00 20 20 20 31 2d 44 45 43 2d 32 30 30 31 20 .. 1- +DEC-2001 01:23:33.....host$ > 0x00000: 6c 6f 0d 0a lo.. 00000: 6c 6f 0d 0a lo..

Replies are listed 'Best First'.
(jeffa) Re: Net:Telnet and Vaxes
by jeffa (Bishop) on Nov 30, 2001 at 21:11 UTC
    Instead of the print() method
    @line = $telnet->print('sh time');
    use the cmd() method
    @line = $telnet->cmd('sh time');
    According to the docs, the print() method "prints a string or a comma-separated list of strings to the opened object and returns non-zero if all data was successfully written."

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: Net:Telnet and Vaxes
by jlongino (Parson) on Nov 30, 2001 at 22:09 UTC
    Although it may not have a bearing on your current problem, you might want to consider doing more error checking on your telnet commands. It's helped with several problems I've encountered:
    . . . . . . . . ## after login attempt my $msg = $telnet->errmsg; die "A system error was generated on login attempt:\n '$msg'\n\n" if + $msg; . . . . . . . . ## after command is issued my @lines = $telnet->cmd("sh time"); my $msg = $telnet->errmsg; die "An error occurred on cmd 'sh time':\n '$msg'\n\n" if $msg;
    HTH.

    --Jim

Re: Net:Telnet and Vaxes
by davis (Vicar) on Nov 30, 2001 at 21:17 UTC
    Perhaps the localtime port would also be of interest. I'm not sure if it'll work on VAXen, but it's accessible via tcp port 13.
    Here's what worked for me:
    #SHELL# telnet localhost 13 Trying... Connected to localhost. Escape character is '^]'. Fri Nov 30 16:14:00 GMT 2001 Connection closed by foreign host. #SHELL#
    May be useful.
    davis
      Thanks for the tip - didn't know about that port! Regards, Stacy.