Skip to content

Instantly share code, notes, and snippets.

@PalmaSolutions
Forked from sanmadjack/sysinfo.motd.pl
Created August 11, 2016 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PalmaSolutions/db8ff687de9d6c402b8ae6362fb419e9 to your computer and use it in GitHub Desktop.
Save PalmaSolutions/db8ff687de9d6c402b8ae6362fb419e9 to your computer and use it in GitHub Desktop.
A MOTD script for displaying system information.
#!/usr/bin/perl
use Data::Dumper;
sub GetIpAddresses{
my $output = qx(ifconfig);
my $hash = {};
my $interface;
foreach my $line (split /[\r\n]+/, $output) {
if($line =~ m/^([^ ]+)/) {
$interface = $1;
}
if($line =~ m/inet addr:([0-9.]{7,15})/) {
$hash->{$interface} = $1;
}
}
return $hash;
}
sub GetPartitionInfo{
my $output = qx(df -T);
my $hash = {};
my $partition;
foreach my $line (split /[\r\n]+/, $output) {
if($line =~ m/^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)$/) {
if (($2 ne 'zfs') && ($2 ne 'tmpfs') && ($2 ne 'devtmpfs')) {
$subhash = {};
$subhash->{'percent'} = $6;
$subhash->{'fs'} = $2;
$hash->{$7} = $subhash;
}
}
}
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
if($username eq 'sanmadjack') {
$output = qx(sudo zpool list);
foreach my $line (split /[\r\n]+/, $output) {
if($line =~ m/^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)$/) {
if (($2 ne 'SIZE')) {
$subhash = {};
$subhash->{'percent'} = $5;
$subhash->{'fs'} = 'zpool';
$hash->{$1} = $subhash;
}
}
}
}
return $hash;
}
print Dumper &GetIpAddresses();
print Dumper &GetPartitionInfo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment