[Israel.pm] Using Perl for Unix System administration

guy keren choo at actcom.co.il
Tue Apr 10 16:12:00 PDT 2007

Gabor Szabo wrote:
> Hi,
> There is a (IMHO) very good page explaining Why Perl? here:
> http://www.perltraining.com.au/whyperl.html
> This has a general explanation.
> I am trying to put together a set of pages explaining why is it good
> to learn and use Perl in various specific fields.
> I started by writing down a few words for Unix System administrators
> with examples from my course.
> http://www.pti.co.il/unix_sysadmin.html
> It would be a great help to both me and the system administrators
> out there if you could give me more ideas what else should I point
> out, what other examples should I show?
> regards
>    Gabor

your 'global search and replace' example is not a good one. it'll be 
much better to show "perl -pni .bak <file list> -e 'bla bla bla'" (or 
even "find .... | xargs perl -pni .bak -e 'bla bla bla'") -  might be 
mistaken on the '-pni' flag sequence - perhaps it's just '-ni' or '-pi'.

the same would go for your 'renaming many files at once' example. if the 
example itself is not superiourly better then using simple shell 
commands (find .... -exec mv {} {}...;) - then it's better not to give 
this as a 'first' example (i.e. in the 'sales peach' like this page).

here are examples where perl _is_ very useful, and not an over-kill:

1. writing an internal web site with an inventory collection for network 
equipment. very easy to do with a cgi-bin perl script. data is stored in 
a flat-file (or even in an open-source SQL database).

2. writing a script that creates a user account, adds the user to a set 
of groups, adds the user to the samba config file, creates an NFS share 
for the user (to mount from other servers) and .....

3. writing a script that connects to a network router, using a telnet 
interface, collects accounting data for a given IP address, then 
summarizes all incoming and outgoing data and prints a report.

4. writing a script, from cron, that collects data about system 
parameters (e.g. ethernet packet loss, etc.). the script adds the data 
to a database. another script takes data from this database, and 
generates hourly-based reports, creating a graph using gnuplot, and 
places that on the web server. a 3rd script, a cgi script, allows 
quering this data and showing it via a web browser. this demonstrates 
how easy it is to build 'systems' in perl, which are made of several 
rather simple scripts.


More information about the Perl mailing list