473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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

Similar topics

9
by: Jean-Marc Molina | last post by:
Hello, I can't find a way to execute a Windows application, whose directory path contains blank spaces, from a PHP script. I also wonder if the problem happens under Linux and other OS. ...
2
by: Jon Maz | last post by:
Hi All, To allow myself to make development changes directly on a remote server *without* having to compile on my local dev machine and then upload the dll's to remote, I have created a...
9
by: Doug at SAU | last post by:
I need to run a batch file on a remote machine from an ASP page. I dummied up a test ASP page as follows: <% Set WshShell = Server.CreateObject("Wscript.Shell") wshshell.run...
2
by: Sinex | last post by:
Hi, I am triggering a batch file from my C# code. There are no echo commands in the batch file...yet the console window/command prompt window pops up every time the batch file is triggerred. Is...
7
by: David R. | last post by:
Hello all, I would like to generate a Sql-Script-File and a Batch-File to execute the Batch-File over C#-Code and use the SQL-File as an Input-File for the command "osql" in the Batch-File. I...
0
by: RajeevSekar | last post by:
Hi Experts, I am trying to invoke a batch(reside in my local machine) file from asp.net using System.diagnostics.process.start("path\filename") method, it is working fine, but when i try to...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
hello Everyone, I created this batch file that executes the taskKill command to kill the process on the remote server. When I call this batch file from the console applications, it runs fine and...
2
jamesd0142
by: jamesd0142 | last post by:
Hi, I have a batch file on a remote server. if i use remote desktop to connect to this server and run the batch file it runs as i would expect. However i need to run this batch file from my...
0
by: =?Utf-8?B?UnVzdHlfUm9zZXI=?= | last post by:
Hi everyone, I'm having some issues figuring out how to complete certain tasks with a batch file, whether it be not knowing the right syntax or if it can even be accomplished with a batch file....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.