Executing a Batch file on Remote Window Machine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajays
    New Member
    • Apr 2007
    • 7

    Executing a Batch file on Remote Window Machine

    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 )

    [CODE=perl]
    push(@INC,'E:\p erl\Net-Telnet-3.03\blib\lib\N et');
    use Net::Telnet ();

    $t = new Net::Telnet(
    Timeout => 10,
    Prompt => '/\$ $/',
    );
    $t->open("X.X.X.X" );
    $t->login('"abc" , 'abc');
    $cd = $t->cmd("cd ajay");
    $comp = $t->cmd("ls");

    print @lines;
    [/CODE]
    Last edited by miller; Jun 29 '07, 04:17 PM. Reason: Code Tag and ReFormatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    I'm not sure about that module but your code isn't valid, like this line:

    Code:
    $t->login('"abc", 'abc');
    the quotes are off, should be:

    Code:
    $t->login('abc', 'abc');
    read the module documentation if you haven't already, there is some info about login problems in the "login" section.

    Comment

    • ajays
      New Member
      • Apr 2007
      • 7

      #3
      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

      [CODE=perl]
      push(@INC,'E:\p erl\Net-Telnet-3.03\blib\lib\N et');
      use Net::Telnet();

      $t = new Net::Telnet (
      Timeout => 20,
      Prompt => '/C:\\\\>$/i',
      Input_log => 'abc.txt',
      Output_log => 'def.txt'
      );

      $t->open("x.x.x.x" );

      $user = 'xxxxx';
      $password = 'xxxxxx';

      $t->waitfor('/login: $/i');
      $t->print($user) ;

      $t->waitfor('/password: $/i');
      $t->print($passwor d);

      $t->waitfor('/.*C.*$/i');
      $t->print ("C:\\\\");

      print $t->cmd('testing.b at');
      $t-Waitfor('D:\\\\ saurabh\\\\test \\\\Source.out\ \\\arm\\\\lib') ;

      $t->print('pwd') ;
      [/CODE]

      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.b at');

      Kindly suggest
      Last edited by miller; Jun 29 '07, 04:29 PM. Reason: Code Tag and ReFormatting

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Sorry, I don't know. Maybe someone else will.

        Comment

        • ajays
          New Member
          • Apr 2007
          • 7

          #5
          actully after print $t->cmd('testing.b at');
          line it sends a message on the command line :

          command timed-out at windows_telnet. pl line 50

          Comment

          • ajays
            New Member
            • Apr 2007
            • 7

            #6
            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

            Comment

            • isha123
              New Member
              • Jun 2007
              • 5

              #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.xx x";
              print "$HOST\n";
              my $USER = "abc";
              my $PASS ="xyz";
              my $telnet = Net::Telnet->new($HOST);
              $telnet->login($USER,$P ASS);
              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"

              Comment

              • isha123
                New Member
                • Jun 2007
                • 5

                #8
                Originally posted by isha123
                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.xx x";
                print "$HOST\n";
                my $USER = "abc";
                my $PASS ="xyz";
                my $telnet = Net::Telnet->new($HOST);
                $telnet->login($USER,$P ASS);
                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.

                Comment

                Working...