Create a gist now

Instantly share code, notes, and snippets.

@ecliptik /Dockerfile
Last active Aug 30, 2015

What would you like to do?
Executable Perl Docker Container
FROM ubuntu:14.04
MAINTAINER Micheal Waltz <ecliptik@gmail.com>
#Setup basic environment
ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C.UTF-8 LANGUAGE=en_US.UTF-8
#Update system and install packages
RUN [ "apt-get", "-q", "update" ]
RUN [ "apt-get", "-qy", "--force-yes", "upgrade" ]
RUN [ "apt-get", "-qy", "--force-yes", "dist-upgrade" ]
RUN [ "apt-get", "install", "-qy", "--force-yes", \
"perl", \
"build-essential", \
"cpanminus" ]
RUN [ "apt-get", "clean" ]
RUN [ "rm", "-rf", "/var/lib/apt/lists/*", "/tmp/*", "/var/tmp/*" ]
#Install cpan modules
RUN ["cpanm", "Proc::ProcessTable", "Data::Dumper" ]
#Copy script.pl and make executable
COPY [ "./ps.pl", "/app/ps.pl" ]
RUN [ "chmod", "+x", "/app/ps.pl" ]
#Set entrypoint of script.pl
ENTRYPOINT [ "/app/ps.pl" ]
#!/usr/bin/perl -w
use strict;
use Getopt::Std;
use Proc::ProcessTable;
# declare the perl command line flags/options we want to allow
my %options=();
getopts("hv", \%options);
if ($options{h})
{
show_help();
}
if ($options{v})
{
show_version();
}
sub show_help {
print "A simple perl version of ps";
exit;
}
sub show_version {
print "Version: 1.0";
exit;
}
#Example from: http://search.cpan.org/~durist/Proc-ProcessTable-0.39/ProcessTable.pm
my $FORMAT = "%-6s %-10s %-8s %-24s %s\n";
my $t = new Proc::ProcessTable;
printf($FORMAT, "PID", "TTY", "STAT", "START", "COMMAND");
foreach my $p ( @{$t->table} ){
printf($FORMAT,
$p->pid,
$p->ttydev,
$p->state,
scalar(localtime($p->start)),
$p->cmndline);
}
# Dump all the information in the current process table
use Proc::ProcessTable;
$t = new Proc::ProcessTable;
foreach my $p (@{$t->table}) {
print "--------------------------------\n";
foreach my $f ($t->fields){
print $f, ": ", $p->{$f}, "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment