#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use File::Temp qw/ tempdir /; # necessary minimum for CGI print "Content-type: text/plain\n\n"; # prepare temp dir my $temp = "/home/www-data"; my $login_user= "xxxxx"; my $login_pass = "xxxxx"; # open SSH session my %opts = ( user => $login_user, password => $login_pass, ctl_dir => $temp, strict_mode => 0 ## NOT recommended - see my comments ); my $ssh = Net::OpenSSH->new("n.n.n.n", %opts); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; # perform command and print output my @lines = $ssh->capture("sh int desc") or die "remote command failed: " . $ssh->error; print "OUTPUT
\n"; print @lines; #### Content-type: text/plain This system is for authorized users only. Unauthorized access is prohibited. --snip-- Logging In
OUTPUT
Last switch-over Thu Dec 29 12:08:33 2016: 6 weeks, 6 days, 1 hour, 52 minutes ago Wed Feb 15 14:00:58.710 cst Interface Status Protocol Description -------------------------------------------------------------------------------- --snip-- ##
## Logging In
##
## This system is for authorized users only. Unauthorized access is prohibited. --snip-- Connection to n.n.n.n closed by remote host. remote command failed: 0 at /usr/lib/cgi-bin/test2.cgi line 34.