Re: Telnet Problem



abdur_rab7@xxxxxxxxxxx a écrit :
Hi All,

I am a new bee to perl, do not know even the basics of perl.

The Scenirion, why i choose perl

I have a exe file compiled with cygwin, need to execute in different
windows machine and get the output as log files, so i chose perl to ftp
the required exe file and execute using the Telnet module. I am having
problem with Telnet as it is not returning after the completion of the
exe, it waits until the time out.

Hello,
I did not use Telnet, but i have a litttle experience in FTP.
To be able to log FTP action in the script, I have redirected STDERR, and STDOUT in the same file. You can try this ..
open ( STDERR ,">>$LOG");
open (STDOUT ,">>$LOG");

select STDERR ;
.....
close (STDERR);
close (STDOUT);



Please find the following perl code

#!/usr/bin/perl -w
use Net::Telnet;
use strict;

my $LOG_FILE="C:\\Temp\\Telnet.log";
my $SOURCE_PATH="C:\\\\SMIProviderInstallation\\\\src";
my $BUFFER_MAX=10485760; #10 MB of Buffer
if (($#ARGV+1)==5)
{
#my $tel_obj = new Net::Telnet (Timeout => 999, errmode => 'die',
Binmode =>0);
my $tel_obj = new Net::Telnet (errmode => 'return', Binmode =>0);
$tel_obj->max_buffer_length($BUFFER_MAX);
$tel_obj->input_log($LOG_FILE);
if(!($tel_obj->open($ARGV[1])))
{
print "Unable to telnet...\n";
return 0;
}

print "\nINFORMATION: Connecting to Host : $ARGV[1]";
$tel_obj->login(Name => $ARGV[2], Password => $ARGV[3]);
#$tel_obj->login($ARGV[2], $ARGV[3]);
$tel_obj->cmd(String => "cd $SOURCE_PATH");
$tel_obj->timeout(999);

print "\nINFORMATION: Executing the exe : $ARGV[4]";
my $cmd_str = "perl $ARGV[4]";
$tel_obj->cmd($cmd_str);
$tel_obj->timeout(0);
$tel_obj->close;

print "\nINFORMATION: Closing the connection with Host : $ARGV[1]";
}
else
{
print "\nERROR: Invalid Argument Passed...\n";
}

It will get four parameters

$ARGV[0] = passing a string - variable currently not used
$ARGV[1] = Host name
$ARGV[2] = User name
$ARGV[3] = Password
$ARGV[4] = script name

the script which needs to be executed contains the following lines

#!/usr/bin/perl -w
system ("execute.exe");
print "\n$?"


Thanks in advance....

.



Relevant Pages

  • Re: /cgi-bin/ directory
    ... telnet sitename.com 80 ... This question has nothing to do with Perl, ... have a Perl problem, and you should post a short-but-complete script ...
    (comp.lang.perl.misc)
  • Re: ways I might parse data in perl and give it to a telnet session
    ... > 1 translate cuecat data(done via larry wall's perl script- don't ... slurp up file with an expect script. ... > interactive program (telnet session) i should be fine. ...
    (perl.beginners)
  • Re: script works from prompt but not through telnet
    ... > when using telnet, ... It looks like you might have two versions of perl installed and that you ... are calling a different interpreter in different environments. ... I assume that when your script works from a command prompt you are ...
    (comp.lang.perl.misc)
  • Re: Totally lost - need a starting point
    ... I have no idea what Expect is, but searching for 'expect' and 'perl' in Google revealed a perl module for expect. ... The other pieces of your problem might include getting form values from an HTML form. ... Yes I have a perl script running inside of the expect script, ... it didn't seem to be able to get the results that I was looking for, being able to telnet into a terminal and offer up passwords and such. ...
    (perl.beginners)
  • telnet.pm
    ... Does some know how to get the output when I send commands to a telnet ... server using a perl script??? ...
    (perl.beginners)