Skip to content

Instantly share code, notes, and snippets.

@DeMarko
Created November 30, 2010 16:47
Show Gist options
  • Save DeMarko/721955 to your computer and use it in GitHub Desktop.
Save DeMarko/721955 to your computer and use it in GitHub Desktop.
Quick and dirty script that displays some sysinfo that I wanted to see in my .login
#! /usr/bin/perl
use Shell qw(hostname date uptime users echo zwrite);
use Term::ANSIColor qw(:constants);
my $hostname = hostname;
chomp($hostname); # remove newline inserted by system command
@usersa = split(/\s/, users); # split users into an array
my $lncount = 80; # so the first line prints proper ^_^U
my $up = substr(uptime, 10); # display server uptime (the timestamp is a bit redudant I guess)
my $time = date; # remember where you're at in time
my %usercount;
foreach $user (@usersa) {
$usercount{$user}++;
}
# in case you are not familiar with perl's ANSIColor constants they are:
# CLEAR, RESET, BOLD, DARK, UNDERLINE, UNDERSCORE, BLINK, REVERSE, CONCEALED
# BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA,
# ON_BLACK, ON_RED, ON_GREEN, ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and ON_WHITE
print BOLD, UNDERLINE, "System stats for $hostname:\n", RESET;
print "At the tone, the time & date will be:\n", RED, " $time", RESET;
print "The following users are on this system:";
foreach $username (keys %usercount) {
if ($usercount{$username} == 1) {
$instances = $username;
} else {
$instances = $username . "($usercount{$username}) ";
}
if(($lncount + length($username) + 1) > 80) {
print YELLOW "\n $instances ";
$lncount = length($instances) + 5;
} else {
print YELLOW "$instances ";
$lncount += (length($instances) + 1);
}
}
print RESET, "\nUptime & Load Info:\n", GREEN, " $up", RESET;
@DeMarko
Copy link
Author

DeMarko commented Nov 30, 2010

I stopped writing perl a while ago, this was originally written freshman year?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment