LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-17-2012, 12:53 AM   #1
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Rep: Reputation: Disabled
Wink calling a shell script present on another server using perl script.


Hi,

I am working on a sever A.
I want to write a perl script to execute a shell script persent on the server B.
please help me in this.

thanks in advance.
 
Old 07-17-2012, 01:58 AM   #2
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
You can easily execute a shell script with ssh:
ssh user@serverB <script-on-serverB>

If you want it to run without asking for password you can set up certificates, there are several guides on internet about that.
 
1 members found this post helpful.
Old 07-17-2012, 03:43 AM   #3
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by pingu View Post
You can easily execute a shell script with ssh:
ssh user@serverB <script-on-serverB>

If you want it to run without asking for password you can set up certificates, there are several guides on internet about that.
thats a basic command, ssh user@servername "command_in-remote-host"

In perl, u can use 3 module.
(1) Net::SSH
(2) Net::SSH::Perl
(3) Net::SSH:Expect

(1) Net::SSH = Here you have to setup RSA or DSA key first. Then you have to use these module in your perl script.
For reference how to setup RSA key. This is in my blog link. http://sharadchhetri.com/2011/11/28/...ordless-login/


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

ssh('user@hostname', $command);

issh('user@hostname', $command);

ssh_cmd('user@hostname', $command);
ssh_cmd( {
user => 'user',
host => 'host.name',
command => 'command',
args => [ '-arg1', '-arg2' ],
stdin_string => "string\n",
} );

sshopen2('user@hostname', $reader, $writer, $command);

sshopen3('user@hostname', $writer, $reader, $error, $command);
(2) Net::SSH::Perl


Quote:
use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
(3) Net::SSH::Expect :

I think in this you have to install expect in your system either by rpm,yum or as per your distro.

Eg. is big so pasting the link.

http://search.cpan.org/~bnegrao/Net-...SSH/Expect.pod
 
1 members found this post helpful.
Old 07-17-2012, 03:44 AM   #4
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by sharadchhetri View Post
thats a basic command, ssh user@servername "command_in-remote-host"

In perl, u can use 3 module.
(1) Net::SSH
(2) Net::SSH::Perl
(3) Net::SSH:Expect

(1) Net::SSH = Here you have to setup RSA or DSA key first. Then you have to use these module in your perl script.
For reference how to setup RSA key. This is in my blog link. http://sharadchhetri.com/2011/11/28/...ordless-login/




(2) Net::SSH::Perl




(3) Net::SSH::Expect :

I think in this you have to install expect in your system either by rpm,yum or as per your distro.

Eg. is big so pasting the link.

http://search.cpan.org/~bnegrao/Net-...SSH/Expect.pod
You have to install these module for perl script.
 
Old 07-18-2012, 12:23 AM   #5
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
Thanks Sharad.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help calling a shell script inside a python script WyoChuck Linux - Newbie 4 05-28-2012 09:39 PM
Shell script calling shell script - List of all nikunjbadjatya Programming 7 04-13-2011 06:27 PM
Calling a bash shell script from within another script dedman Linux - Software 7 04-24-2010 08:53 PM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration