by Jeremy Canfield | Updated May 19th, 2018
This assumes you have installed the Net::SSH::Perl module on your system.
Create an SSH connection to another host.
#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; my $host = "your_hostname"; my $user = "your_username"; my $pass = "your_password"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd("type the commands you want to run on the remote host here"); print "Standard Out: $stdout\n"; print "Standard Err: $stderr\n"; print "Exit Code: $exit\n";
Running the script will produce the following output.
Standard Out: name.example.com Standard Err: Exit code: 0