Solved

SSH to Linux from windows in Perl

Posted on 2009-05-10
4
1,642 Views
Last Modified: 2012-05-06
I need to SSH to a linux box, from a windows box, and run some interactive commands to do an installation. And I have to user perl to accomplish this.

So I have run a perl script on a windows box, that will then ssh to the linux box and run commands one after the other interactively... I will have to answer in yes/no or select from 1,2,3 etc.

Is there a way to do this? I am not sure if I have provided enough information but I can answer any questions if someone has suggestions.

Thanks.
0
Comment
Question by:pavanbh
4 Comments
 
LVL 28

Accepted Solution

by:
FishMonger earned 168 total points
ID: 24348751
0
 
LVL 8

Assisted Solution

by:thetmanvn
thetmanvn earned 166 total points
ID: 24348892
Very details example using perl ssh to execute shell remotely via ssh

http://www.example-code.com/perl/ssh_exec.asp

More sample code:
http://www.example-code.com/perl/ssh_remote_command.asp
http://www.example-code.com/perl/ssh_tunnel.asp

Hope this help
0
 
LVL 2

Assisted Solution

by:jccs0519
jccs0519 earned 166 total points
ID: 24357365
If you just need Perl example or module the other comments should work for you.

If you're looking for an environment to do this on a Windows box, then you'll need to install Cygwin, there might be other solution but Cygwin works for me.  I did the same thing before using this app.

Cygwin is basically a bunch of Unix utilities that'll work on Windows command prompt.  Once installed, it'll popup like a Windows command prompt, except you can use a lot of unix utilities like ls, ssh/scp, bash scripts.  When you install you can choose what package or utilities you want to include.  I've even ran X-windows on top of Cygwin where I can remotely export X-Windows tools from a remote server like Sun Solaris admin tools.  I also has setup perl scripts to access mysql DB using cygwin before.

Anyway, in  your case, you'll need perl and ssh package.  Once install, setup ssh keys where you can access linux server without password.  ssh-keygen -t rsa, copy key to linux .ssh/authorized_keys, ensure 755 in user login, but 600 in .ssh directory.  Then you can write your perl or shell script to access the linux server.  You can remotely exec commands via ssh (ie. $ ssh linuxbox ls -l).

Hope that helps
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML::LibXML and Xpath syntax How do I get attribute of sibling 2 148
Specific format 21 207
countHi2 challenge 7 60
Log File Creation with Header and Footer 17 128
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to implement Singleton Design Pattern in Java.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question