1819965 Members
3439 Online
109607 Solutions
New Discussion юеВ

ssh - PERL

 
Anand_30
Regular Advisor

ssh - PERL

hi,

I am using ssh in my PERL script.

The pur pose of my script is to log into a remote machine and execute a perl script there which takes a minute or so to execute. The remote perl script creates a report and I need to cp that report to my machine using "scp".

The portion of my script which does this is as following:

my $cmd = "ssh user\@password perl report.pl";
my @result = `$cmd`;
print @result;

I don't get any errors but the output is never created in the remote machine.

I just receive the message:

"Please wait while your request is getting processed" which is the message from the remote perl script while creating the output.


Even if I just use ssh from command line, I don't see any errors but the output file is not cretaed in the remote machine. Here also I just get the "Please wait" message and then it returns to the command prompt.

Can anyone please tell me how do I make the ssh session to wait till the output file is created by the perl script in the remote machine.

Thanks,javascript:postMessageSubmit('submit');
Submit
Anand

9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: ssh - PERL

Shalom,

perl has a command called system, which I use for these purposes.

You may be doing it differently, but you may wish to try that.

ssh is on the PATH?

Perhaps try the full path of this in the shell.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
A. Clay Stephenson
Acclaimed Contributor

Re: ssh - PERL

I would suggest that you use the Net::SSH module to do whatever you need to do.

http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm
If it ain't broke, I can fix that.
Alzhy
Honored Contributor

Re: ssh - PERL

I agree with Sensei A. Clay.

system() should be outlawed in Perl shell scripts as do direct calls to commands like ssh/ftp,etc. Most common tools/utils now have their corresponding Perl Modules on CPAN.

I am starting to get serious with Perl these days and I was amazed at the many really useful modules at CPAN that were not there last time I looked ( long time...).
Hakuna Matata.
H.Merijn Brand (procura
Honored Contributor

Re: ssh - PERL

1. system () should not be outlawed, as it is VERY useful. Do not propagate wrong answers

2. The problem with many, if not all, SSL/SSH related perl modules is that most are XS based modules that require to be compiled with the C compiler. That is however not the biggest problem, as the GNU gcc compiler is widely available, and causes less and less trouble with every new release.
The trouble comes with ssl/ssh related source files needing the development files of ssl/ssh, and I've seen too often that these are either not available at all, or that the wrong version is available (32bit where 64bit is needed or vice versa).
The latter causes more headaches than it solves, and warrents the use of external ssh/scp/ftp calls through system () or qx// in your scripts.

Enjoy, Have FUN! H.Merijn [ who tries to include SSH modules in his perl builds wherever possible ]
Enjoy, Have FUN! H.Merijn
Arunvijai_4
Honored Contributor

Re: ssh - PERL

Hi Anand,

Net::SSH will be helpful to you,

http://www.stupidfool.org/perl/net-ssh/
http://www.stupidfool.org/perl/docs/perldoc/Net/SSH/Perl.html

Procura, how about using this module ? Or it is included in your latest Perl (5.8.8 or 5.8.7) build ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
H.Merijn Brand (procura
Honored Contributor

Re: ssh - PERL

I've listed what is included on my site too: http://mirrors.develooper.com/hpux/#Perl

Crypt::SSLeay, Net::SSLeay, & IO::Socket::SSL

Net::SSH is not included (yet). I'll consider including it in the upcoming releases.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: ssh - PERL

Net::SSH is just a perl wrapper around the system calls. I've just browsed the code, and found:

--8<---
sub ssh {
my ($host, @command) = @_;
@ssh_options = &_ssh_options unless @ssh_options;
my @cmd = ($ssh, @ssh_options, $host, @command);
warn "[Net::SSH::ssh] executing ". join (' ', @cmd). "\n"
if $DEBUG;
system (@cmd);
}
-->8---

Which I find a bit simplistic, and certainly not good enough a reason to include this module.

A better solution would be to use Net::SSH::Perl, which is a perl implementation that does not use the external commands, but this module has too many dependancies (*) to add it to my distribution(s). So I will probably not do so.

(*) PREREQUISITES

Protocol 1

* Math::GMP (1.04 or greater)
* String::CRC32 (1.2 or greater)
* Digest::MD5
* IO::Socket

Protocol 2

* Crypt::DSA (0.03 or greater)
* Crypt::DH (0.01 or greater)
* Math::Pari (2.001804 or greater)
* MIME::Base64
* Digest::MD5
* Digest::SHA1
* Digest::HMAC_MD5
* Digest::HMAC_SHA1
* Convert::PEM (0.05 or greater)
* IO::Socket

It also optionally requires Digest::BubbleBabble for
generating bubble babble fingerprints, and Crypt::RSA
(1.37 or greater) if you want to use RSA key files in SSH2.

Note that RSA key files in SSH1 do not require Crypt::RSA.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Anand_30
Regular Advisor

Re: ssh - PERL

Hi,

I used the PERL SSH module and it worked fine. Thanks to all of you.

Anand
Patrice Le Guyader
Respected Contributor

Re: ssh - PERL

Hello,

Why not using expect with ssh ? I have open a thread on it and Doug O'Leary answer me. Have a look.

Best Regards
Patrice
Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.