GaijinPunch has asked for the wisdom of the Perl Monks concerning the following question:

I've got two issues here. The overall goal here is to have a perl script run 'ps -ef |grep blah blah' on some remote hosts. For most machines, I can use RSH, but for some, I'm stuck with SSH. The kicker is, this is a cgi script so the apache user is the one doing the execution.

I'm using Net::SSH::Perl, but am getting no where. Here's the simple script I've got to test it.
my $ssh = Net::SSH::Perl->new('host'); $ssh->login('user','pass'); my ( $stdout, $stderr, $exit ) = $ssh->cmd('uptime'); print qq(Content-type: text/html ); print "output from ssh: $stdout\n"; print "error from ssh: $stderr\n"; print "</html>\n";
When I run this through the browser, I get the following error:
mkdir /.ssh: Permission denied at /usr/lib/perl5/vendor_perl/5.8.4/Net +/SSH/Perl/Util/Hosts.pm line 50
It looks to me as if it's trying to create a .ssh directory in / (which it obviously doesn't have permission to do). /etc/passwd says that apache's homedir is /home/httpd.

EDIT: The 2nd problem is fixed... the remote machine I was testing with was my little personal romping ground, to which I probably broke last night goofind around w/ the sshd_config.

Replies are listed 'Best First'.
Re: SSH::Net::Perl and Apache
by GaijinPunch (Pilgrim) on Jun 15, 2005 at 01:03 UTC
    Okay, I made /.ssh and chowned it to apache and it works now.... kind of ghetto style, but oh, well. Too bad I can't give myself repuation points.
      I'm having the exact same problem. You said you created the .ssh and made Apache the owner. Can you tell me where? I know that sounds stupid - but I am!

      Also, I wanted to expand this - I wans perl to start a cgi script under the user/pass used in Net::SSH::Perl. Can I do that?