szabgab has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to put together a page with examples on how to use Perl for Unix System Administration. I included some text already and several examples from my course material but I would appreciate to see your ideas on what else to include.

Replies are listed 'Best First'.
Re: Perl for Unix System Administration
by Old_Gray_Bear (Bishop) on Apr 10, 2007 at 15:34 UTC
    Take a look at David Blank-Edelman's Perl for System Adminstration for a good set of Admin tools. Dave covers both Unix and Windows in the book, and it's worth reading the sections that cover the 'other' operating system (which ever OS you aren't using) to get a perspective on a different way to approach the fundamental challenges of the SA's job. There are a lot of 'out of the box' solutions in the book and it provides enough basic information to act as a spring board into the deeper end of the SysAdmin pool.

    Highly Recomended, Bear-Bob says: "Check It Out"

    ----
    I Go Back to Sleep, Now.

    OGB

      Yeah, that's one of the books I already recommend on the page.

      I am interested in examples AdminMonks use.

Re: Perl for Unix System Administration
by Moron (Curate) on Apr 10, 2007 at 15:30 UTC
    I would add:

    - a script to add or modify a unix user account, including creation of home directory and site-specific initialisation of that directory.

    - a script to do full or incremental backup/restore

    - a script (or more likely a collection daemon and a reporting script) to monitor user behaviour including disk usage.

    -M

    Free your mind

Re: Perl for Unix System Administration
by naikonta (Curate) on Apr 10, 2007 at 16:13 UTC
    This is another great craft from ++Gabor after CPAN::Forum. It's just simple and right to the point without gory details. And I'm sure that the examples will grow and grow. Perhaps you could add about service monitoring or quota alert?

    I have my simple one myself you might want to consider. It's just another mass file operation type, similiar to the traverse file system stuff. But rather, mine's task is performing file permission changing (chmod), specifically, adding or repairing them to put 'w' bit for group. I'm not quite sure actually if this can be seen as sysadmin job. I usually run it for sharing purpose, for other users within the same group. However, the modes are customizable via command line options. Here it goes (I use -s for simpel CLO parsing).

    #!/usr/bin/perl -ws use strict; use vars qw($f $d); use File::Find; my $start_dir = shift || '.'; my $dir_mode = $d ? oct($d) : 0775; my $file_mode = $f ? oct($f) : 0664; find \&wanted, $start_dir; sub wanted { my $mode = -d() ? $dir_mode : $file_mode; chmod $mode, $_ or die "Can't chmod $_: $!\n"; } __END__
    Oh, a little note about this,
    Writing an Excel file. (example coming soon). Many times we are required to create reports in text format. That's easy with Perl, that's what the Reporting part of the name Perl came from.
    While it's a nice say, nevertheless, the name Perl was and is never meant as an acronym. The "Practical Extraction and Reporting Language" came later.
      Oh I did not mean THAT! I promise :-)

      Changed the partial reference to "Practical Extraction and Reporting Language" that might offend some of us ;_)

        I know you didn't, but before someone offensed and comes to punish you... :-)

        Perl name explanations eh? Hmm, I like that, sounds friendlier than retronym.

Re: Perl for Unix System Administration
by deeknow (Novice) on Apr 12, 2007 at 04:07 UTC

    Coming at this from a web perspective, here's some admin tools I've written in Perl which I use frequently from the command-line. Feel free to use, borrow, modify (or criticise :-)

    WebConf: grep stuff out of the apache, samba, passwd and group files and the like...
    http://webdev.co.nz/Perl/WebConf

    MetaGeta: read STDIN for a list of HTML filenames, each of which is parsed looking for meta-data and URLs...
    http://webdev.co.nz/Perl/MetaGeta