perl scripts not workin

Support for webhosts that use CentOS
Post Reply
Mr_G
Posts: 6
Joined: 2010/09/07 05:30:24
Contact:

perl scripts not workin

Post by Mr_G » 2010/09/07 06:50:29

Hi,

I am using a cent os with an apache server.

I have an issue with perl scripts, I have gone ahead I installed the perl modules from cpan for ssh and below is my script

#!/usr/bin/perl -w

use Net::SSH::Perl;

my $host = "hostname";
my $user = "user";
my $password = "pass";

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
$ssh->login($user, $pass);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("ls -a");

When I run the script I get the below error

Name "main::pass" used only once: possible typo at ./test.pl line 12.

I wan to use perl to ssh to the multiple servers and check the logs files and display the output in a web browser.

Any alternative scripts will also be helpful

Thanks
Mr_G

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

perl scripts not workin

Post by pschaff » 2010/09/07 09:55:08

Welcome to the CentOS fora. The following reading is recommended for new users:
[url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=14274&forum=47]Readme First[/url]
[url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=14408&forum=47]Installing Software[/url]
[url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=14273&forum=47]Where to Find Answers[/url]
[url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=25128&forum=47]How to provide information about your system[/url]

It is usually better to install packages rather than using cpan.

Please provide the results of [b]./getinfo.sh package[/b] from the 4th link above, and [code]rpm -q php[/code]

May want to look at RPMforge packages[code]
[root@poq1 ~]# yum --enablerepo rpmforge search perl ssh
Loaded plugins: allowdowngrade, downloadonly, fastestmirror, priorities
Loading mirror speeds from cached hostfile
* rpmforge: fr2.rpmfind.net
Excluding Packages from Red Hat Enterprise 5 - RPMforge.net - dag
Finished
525 packages excluded due to repository priority protections
====================================== Matched: perl, ssh ======================================
perl-IPC-Session.noarch : Drive ssh or other interactive shell, local or remote
perl-Net-OpenSSH.noarch : Perl module named Net-OpenSSH
perl-Net-SFTP-Foreign.noarch : SSH File Transfer Protocol client
perl-Net-SSH.noarch : Perl extension for secure shell
perl-Net-SSH-Perl.noarch : Perl client interface to SSH
perl-Net-SSH2.x86_64 : Perl module that implements support for the SSH 2 protocol via libSSH2
perl-SVN-Push.noarch : Push Repository to Remote Subversion Repository
...
[/code]

Bigus
Posts: 3
Joined: 2010/09/07 14:32:55

Re: perl scripts not workin

Post by Bigus » 2010/09/07 14:53:57

You're handing the variable $pass to the login function, but you have defined $password.

"use strict;" in your script would have revealed this and is good practise.

Mr_G
Posts: 6
Joined: 2010/09/07 05:30:24
Contact:

Re: perl scripts not workin

Post by Mr_G » 2010/09/09 15:05:18

I did Google it out and and I installed the module from rpm forge

[code] yum list perl-Net-SSH-Perl
Loaded plugins: fastestmirror
Installed Packages
perl-Net-SSH-Perl.noarch 1.34-2.el5 installed[/code]

Below is the command output you requested.

[code] rpm -q php
php-5.2.13-1.el5.art[/code]

I am just not sure if the cpan module and the rpmforge module will work together.

I used strict and modiied the variable and now my code is as follows

#!/usr/bin/perl -w

use strict;
use Net::SSH::Perl;

my $host = "host";
my $user = "user";
my $password = "passwrd";

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
$ssh->login($user, $password);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("ls -a");


the error now is

./test.pl
Connection closed by remote host. at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Kex.pm line 146
[Moderator edit: Manually fixed formatting for [i]code[/i] sections.]

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: perl scripts not workin

Post by pschaff » 2010/09/09 15:26:01

The "code" widget () is brain-damaged and removes any . :-( You need to manually paste formatted input between [code]...[/code] tags.

That php is from a 3rd party (.art ?) repo. RPMforge packages are likely to mix badly with both cpan modules and foreign php versions. You did not provide the requested getinfo.sh output.

All bets are off.

Post Reply

Return to “CentOS 5 - Webhosting Support”