Hey there!
Today I wanted to focus on something that’s helping me do my job in a more efficient fashion. At a former workplace, I was responsible for ~200 high capacity webhosting machines, and a host of supporting machines. Back then, I was a huge fan of a management system mostly comprised of SSH Keys and a ton of bash scripts. It worked, quite well for the time, but if I could do it again, I’d go with a slightly more refined approach, which is what we’ll discuss today.
So, let’s get started. The first thing you’ll need is a working perl installation, a few devel libs and a handful of perl modules.
yum install gmp-devel
perl -MCPAN -e 'install Crypt::DH , Math::GMP, Net::SSH::Perl'
This is going to install the GMP math development libraries necessary for Math::GMP to compile. Math::GMP and Crypt::DH are prereqs for Net::SSH::Perl.
So once this is done, we can proceed.
#!/usr/local/bin/perl -w
use strict;
use warnings;
require Net::SSH::Perl;
#declare our login vars...
my $user = "root";
my $password = "SEKUREPASSWORD";
my $server = "localhost";
#Setup our SSH Connection...
my $ssh = Net::SSH::Perl->new($server,port=>22,use_pty=>1);
#Initiate out conneciton to the server...
$ssh->login($user, $password);
# Declare our variable for the request...
my $uptime;
# Run our SSH Command and retrieve the output...
($uptime) = $ssh->cmd("/usr/bin/uptime");
print "\n$uptime\n";
exit 0;