Telnet Problem

Telnet Problem

am 08.12.2006 11:06:19 von abdur_rab7

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.

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....

Re: Telnet Problem

am 14.12.2006 09:37:07 von Olivier Mougin

abdur_rab7@yahoo.co.in 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....
>