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

I'm using telnet to connect to another computer and using the the cmd command to send commands. My problem is that sometimes the return value from cmd is the command i just sent. Has anyone ever had this problem or know how to fix it?

Replies are listed 'Best First'.
Re: Telnet Problem
by sauoq (Abbot) on Jul 11, 2003 at 00:31 UTC

    Quoting from the Net::Telnet pod:

    Many command interpreters echo back the command sent. In most situations, this method removes the first line returned from the remote side (i.e. the echoed back command). See cmd_remove_mode() for more control over this feature.

    It might help if you explained your problem in more detail. You might provide some code or at least try to characterize when cmd() returns the command you sent. You could also provide information like what shell is being used on the remote side and what command you see this behavior with.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Telnet Problem
by Mago (Parson) on Jul 15, 2003 at 18:22 UTC
    use Net::Telnet (); my $tn; # TELNET connection initilized sub TNcommand { my($command) = $_[0]; &RunLog (" : Running command = $command"); $tn->cmd(String => $command, Prompt => '/\>$/'); return; } sub TNprint { my($command) = $_[0]; &RunLog (" : Running print command = $command"); $tn->print("$command"); return; } sub TNwriteFile { my($out_fname) = $_[0]; my($NextLine) = "1"; open (SAIDA, ">$out_fname"); while ($NextLine) { if ($NextLine = $tn->getline(Timeout => 15)) { $NextLine =~ s/\r//; print SAIDA $NextLine; } } close SAIDA; return; }
Re: Telnet Problem
by neilwatson (Priest) on Jul 11, 2003 at 12:57 UTC
    Please, please consider using a Net::SSH module. Telnet is very insecure. I really don't understand why so many still insist on using it.

    Neil Watson
    watson-wilson.ca

      I'm going to throw in my two cents and agree with Mr. Watson here. You should definitely be using the Net::SSH rather then the Net::Telnet. SSH is far more secure.

      There are times where the device in question is not SSH capapble or aware. For example: some older terminal servers, switches and hubs. If you are unfortunate enough to be in an environment where they never throw outmoded stuff away like I do you may end up writing scripts to deal with them.

      It ain't time to deprecate Net::Telnet yet.


      Peter L. BergholdBrewer of Belgian Ales
      Peter@Berghold.Netwww.berghold.net
      Unix Professional