469,280 Members | 1,823 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

Executing a Batch file on Remote Window Machine

7
I have a situation where i have to execute a Batch script on Remote Windows Machine (MACH2) from my local machine (MACH1). I was able to do this from windows machine to Linux machine but not able to do this from windows machine to windows machine.

Because when i coonect to windows machine MACH1 to anothe windows machine MACH2 using telnet , it ask for a (y/n) from the user , which i'm not able to provide in script (written below )

Expand|Select|Wrap|Line Numbers
  1. push(@INC,'E:\perl\Net-Telnet-3.03\blib\lib\Net');
  2. use Net::Telnet ();
  3.  
  4. $t = new Net::Telnet(
  5.     Timeout => 10,
  6.     Prompt => '/\$ $/',
  7. );
  8. $t->open("X.X.X.X");
  9. $t->login('"abc", 'abc');
  10. $cd = $t->cmd("cd ajay");
  11. $comp = $t->cmd("ls");
  12.  
  13. print @lines;
  14.  
Apr 20 '07 #1
7 13848
KevinADC
4,059 Expert 2GB
I'm not sure about that module but your code isn't valid, like this line:

Expand|Select|Wrap|Line Numbers
  1. $t->login('"abc", 'abc');
the quotes are off, should be:

Expand|Select|Wrap|Line Numbers
  1. $t->login('abc', 'abc');
read the module documentation if you haven't already, there is some info about login problems in the "login" section.
Apr 20 '07 #2
ajays
7
I'm able to connect to remote windows machine using the Perl script.
Using that perl script i was able to execute a batch script present on the remote windows machine.

But one complication is still there , i was able to send only one command to that machine , and i have to send many ,.

I have this script

Expand|Select|Wrap|Line Numbers
  1. push(@INC,'E:\perl\Net-Telnet-3.03\blib\lib\Net');
  2. use Net::Telnet();
  3.  
  4. $t = new Net::Telnet (
  5.     Timeout => 20,
  6.     Prompt => '/C:\\\\>$/i',
  7.     Input_log => 'abc.txt',
  8.     Output_log => 'def.txt'
  9. );
  10.  
  11. $t->open("x.x.x.x");
  12.  
  13. $user = 'xxxxx';
  14. $password = 'xxxxxx';
  15.  
  16. $t->waitfor('/login: $/i');
  17. $t->print($user);
  18.  
  19. $t->waitfor('/password: $/i');
  20. $t->print($password);
  21.  
  22. $t->waitfor('/.*C.*$/i');
  23. $t->print ("C:\\\\");
  24.  
  25. print $t->cmd('testing.bat');
  26. $t-Waitfor('D:\\\\saurabh\\\\test\\\\Source.out\\\\arm\\\\lib');
  27.  
  28. $t->print('pwd');
  29.  
I'm not able to execute that last line of the above script.Means i was not able to execute any command after
print $t->cmd('testing.bat');

Kindly suggest
Apr 25 '07 #3
KevinADC
4,059 Expert 2GB
Sorry, I don't know. Maybe someone else will.
Apr 25 '07 #4
ajays
7
actully after print $t->cmd('testing.bat');
line it sends a message on the command line :

command timed-out at windows_telnet.pl line 50
Apr 26 '07 #5
ajays
7
Has anybody tried running multiple commands on the remote windows machine
using the Batch script.
Because i'm able to run only one command on the remote window machine.

Kindly suggest , Looking forward to replies
Apr 30 '07 #6
Hi Ajay,

I am facing the same problem....

I have to do telnet on remote machine and it asks to enter (y/n). How did u solve the problem???

following is my code....

use strict;
use Net::Telnet;
my $HOST = "xxx.xxx.xxx.xxx";
print "$HOST\n";
my $USER = "abc";
my $PASS ="xyz";
my $telnet = Net::Telnet->new($HOST);
$telnet->login($USER,$PASS);
my @lines = $telnet->cmd('dir');
print @lines;


when i run this script i get an error "login failed: bad name or password at tel.pl line 12"
Jun 29 '07 #7
Hi Ajay,

I am facing the same problem....

I have to do telnet on remote machine and it asks to enter (y/n). How did u solve the problem???

following is my code....

use strict;
use Net::Telnet;
my $HOST = "xxx.xxx.xxx.xxx";
print "$HOST\n";
my $USER = "abc";
my $PASS ="xyz";
my $telnet = Net::Telnet->new($HOST);
$telnet->login($USER,$PASS);
my @lines = $telnet->cmd('dir');
print @lines;


when i run this script i get an error "login failed: bad name or password at tel.pl line 12"

Here I would also like to add that the ip address is of my local machine only..... and the username and password are also correct.
Jun 29 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Doug at SAU | last post: by
2 posts views Thread by Sinex | last post: by
reply views Thread by RajeevSekar | last post: by
reply views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
jamesd0142
2 posts views Thread by jamesd0142 | last post: by
reply views Thread by =?Utf-8?B?UnVzdHlfUm9zZXI=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.