Last active
April 7, 2022 21:02
-
-
Save sanmadjack/7159897 to your computer and use it in GitHub Desktop.
A MOTD script for displaying system information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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