Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How can I connect to a Linux Machine from a Windows Box

by blackadder (Hermit)
on Apr 05, 2007 at 12:12 UTC ( [id://608462] : note . print w/replies, xml ) Need Help??


in reply to Re: How can I connect to a Linux Machine from a Windows Box
in thread How can I connect to a Linux Machine from a Windows Box

Thanks for the reply so far

What I am trying to do is to automate the patch upgard/install process on our LINUX servers. The manual process would've been done by logging in (root user and password) to this particular Linux server using a putty session, getting a directory listing, then creating a directory in /temp, copying a .tar file from my local windows PC to this folder, extracting it and then running the setup program...Simple

However I have started with this 2 codes - for which both didn't work!!
#! c:/perl/bin/perl.exe use strict; use warnings; use Net::FTP; my $ftp = Net::FTP->new("149.149.149.149", Debug => 0) || die "Cannot +connect $@\n";
The error i got back was:
C:\Scripts>ESX_conn2.pl Cannot connect Net::FTP: connect: Unknown error

and then I tried
#! c:/perl/bin/perl.exe use strict; use warnings; use IO::Socket; my $Sock = IO::Socket::INET->new('149.149.149.149',80) or die "Cannot +connect $@\n"; $Sock->read(my $data, 1024) until $Sock->atmark;
I got this error
C:\Scripts>ESX_conn.pl Cannot connect IO::Socket::INET: Cannot determine remote port
I would be greatfull for an example code where a connection is made to a Linux machine (either using IP address or host name) from a windows XP box!

Utmost Regards

Blackadder

Replies are listed 'Best First'.
Re^3: How can I connect to a Linux Machine from a Windows Box
by marto (Cardinal) on Apr 05, 2007 at 12:20 UTC
    You say you connect via putty on your XP machine to these Linux machines. Are you sure you have the correct protocol? Are you actually using SSH? If so take a look at Net::SSH, as mention previously in several of the other replies to your first post in this thread?

    Hope this helps

    Martin
      Hi

      "....Are you sure you have the correct protocol? Are you actually usin +g SSH? "
      Erm, all I know is that I use a Putty session to connect (via port 22, I've just checked it). I enter user= root and the password and hey presto I am in. I want to do just this is in a script!

      Anyway this is what I've tried
      use Net::SSH qw(sshopen2); use strict; my $user = "root"; my $host = "149.195.49.155"; my $cmd = "ls -l"; sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_\n"; } close(READER); close(WRITER);
      And this is what I got!!:
      C:\Scripts>esx_conn3.pl 'ssh' is not recognized as an internal or external command, operable program or batch file.
      An example code would be great.

      Does this help? Cheers.

      Blackadder
        By default SSH runs on port 22, so yes you need to connect using the SSH protocol. Regards example code, did you read the documentation? There are examples there. The error message you are getting is because you have:

        use Net::SSH qw(sshopen2);

        when you want something like:

        use Net::SSH qw(ssh issh sshopen2 sshopen3);.

        Again, read the documentation for a further information and example code.


        Update: Crapola, please ignore the part of this post which has been struck out. Thanks to ikegami for pointing out my mistake.

        Hope this helps

        Martin
Re^3: How can I connect to a Linux Machine from a Windows Box
by regexes (Hermit) on Apr 05, 2007 at 12:54 UTC
    Hello,

    Since you didn't have a Net::Telnet example.... I find that it works well for me. It shouldn't matter if you're on a Windows box or not. As long as the telnetd is running on the Linux machine.
    Of course, I use this in an internal network.
    my $host = "host123"; my $username = "bobjones"; my $password = "mypassword"; my $thost = new Net::Telnet( Timeout => 20, Host => $host, Errmode => "return" ); $thost->login( $username, $password ); my $prompt = "_MYPROMPT_"; $thost->prompt("/$prompt\$/"); $thost->cmd("set prompt = '$prompt'"); # depends on the shell in +use. my $command = "ls"; my @out = $thost->cmd($command); $thost->close;
    getting a directory listing, then creating a directory in /temp, copying a .tar file from my local windows PC to this folder, extracting it and then running the setup program...

    All of the above can be done with Net::Telnet... (I don't know about the copying... I haven't tried that. I usually use Net::FTP for that..)

    Hope it helps...
    regexes


    -------------------------
    Cave ab homine unius libri
      Thanks

      I will try it

      I am having a look at this node as well
      http://www.perlmonks.org/?node_id=538184
      Blackadder
      HELP!

      I have tried this
      #! c:/perl/bin/perl.exe use strict; use Net::SSH::Perl; use Net::Telnet; my $ssh = Net::SSH::Perl->new("RVM701"); $ssh->login("root", "password");
      And I got this in retun!
      F:\SDK\Scripts\D&A>vmlicecheck1.pl The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Per +l.pm line 110.
      Then I tried this
      my $host = "RVM701"; my $username = "root"; my $password = "password"; my $thost = new Net::Telnet( Timeout => 20, Host => $host, Errmode => "return" ); $thost->login( $username, $password ); my $prompt = "_MYPROMPT_"; $thost->prompt("/$prompt\$/"); $thost->cmd("set prompt = '$prompt'"); # depends on the shell in +use. my $command = "ls"; my @out = $thost->cmd($command); $thost->close;
      And this was the result!
      F:\SDK\Scripts\D&A>vmlicecheck1.pl Can't call method "login" on an undefined value at F:\SDK\Scripts\D&A\ +VmLicechec k1.pl line 24.
      Please, Can I rely on your legendry kindness and get enlightenment on what’s wrong and how can I rectify this please? Thanks indeed

      Cheers

      ********************* UPDATE *************************

      Only SSH service is available on the linux servers! cannot use FTP or Telenet!

      Any Clues for me Please?
      Blackadder