My job deals with FreeBSD server, 90% of my time. Daily routines includes checking server health status. FreeBSD has these periodic scripts that will report server health status to sysadm daily, but the emails are always being "ignore" as the info in it are too vast. So, i decided to cough out a simple Perl script that will use SSH to connect to the servers and pull some health status report. This post will talk about using cpan module's, NET::SSH::Perl, to execute commands then print out the results.
Purpose of this script :
- connect to server using ssh
- authenticate only using public key
- run a command and print out the result
Perl modules used :
- Perl::Critic = perl's best practice
- Net::SSH::Perl = the basic of using ssh in perl
- Net::SSH::Perl::Key::RSA = authenticate using public key
- Class::ErrorHandler = needed by Net::SSH::Perl::Key::RSA module
To reduce the hiccups, install the modules listed above by using CPAN client.
Here is the script :