Wednesday, April 23, 2008

a study aid for the Linux+ exam: perlreadsome (Man Pages)

While I was studying for my Linux+ exam I was unable to
find a utility to cycle through all the administrative
man pages on my computer. I wrote the script below for
this purpose.

At some point I may put it up on sourceforge (by that
time it might even work on a non-ubuntu linux computer)
, but for now I just wanted it off of my eee pc before
I blow it away and install Ubuntu 8.04 on it.



#!/usr/bin/perl
#
# Perl Read Some (Man Pages) version 0.01
#
# this script was written by sam levine (hn darkscyon dn
# gmail tld com).
# it come with NO WARRANTY at all. it is licensed
# under the GPL (Gnu Public License)
# I am a noob programmer. this may make your computer
# explode. YOU HAVE BEEN WARNED.
#
# what this script is designed to do:
# Enable you to study man pages.
#
# while I was studying for my Linux+ test I read man
# pages a lot to prepare.
# doing so was a pain in the arse. I decided to write
# this script for fun,
# and hopefully to help other people prepare for the
# test (this may be helpful for
# the LPIC tests as well.

#
#@pages = qw[ man ls ping fdisk ifconfig ];
print "create the manlist? (press y then enter)
\n"; # this creates the list of pages to read
chomp($wait = <STDIN>);
if ( $wait eq 'y' ) {
open MANLIST, "> manlist.sav"; #
# this overwrites any file named manlist.sav in the
# same folder as the script.
select MANLIST;
print ""; #clear manlist.sav
close MANLIST;
select STDOUT;
print "cleared the manlist.sav file\n";
# user feedback is important


@input = `ls /usr/share/man/man8/`; # create an
# array with all the admin man pages
# need to determine the location of this
# and make it portable.

foreach (@input) {
s/[\.]+.+$//;
# remove everything after the . in the file name
open MANLIST, ">> manlist.sav";
select MANLIST;
print; # add the page to the file
close MANLIST;
select STDOUT;
}
print "Just made the manlist.sav file.
Press Enter to continue\n"; # I love feedback ;)
chomp($wait = <STDIN>);
}

open MANLIST, "manlist.sav";

foreach $item (<MANLIST>) {
push(@pages, $item); # create an array with all
the pages in the manlist.sav file
}

# print "$pages[1]\n";
# print "$pages[2]\n";
# print "$pages[ -1 ]\n";

#$page = 'man';
foreach $page (@pages) {
#$maning = `man $page`;
system "man $page"; # read the man page
#print $maning;
push(@pages, $page);
# copy the first item to the last item
shift @pages; # remove the first item
print "\nCare to quit?
please press q then enter\n";
chomp($wait = <STDIN>);
if ( $wait eq 'q' )
{
print "saving the manlist\n";
open MANLIST, ">manlist.sav";
select MANLIST;
print ""; # clear manlist.sav
open MANLIST, ">>manlist.sav";
select MANLIST;
# recreate the manlist.sav file with the new organized list of pages
foreach $page (@pages) {
print $page;
}
close MANLIST;
select STDOUT;
last;
}

}

No comments: