Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Utility Scripts

by vroom (Pope)
on Feb 02, 2000 at 10:42 UTC ( #2712=sourcecodesection: print w/ replies, xml ) Need Help??
Tk Quick Benchmark Tool
on Sep 22, 2002 at 04:54 UTC
by hiseldl
This script is a user interface for comparing short snippets of code and was inspired by BrowserUk, bronto, and Aristotle at this node. There are several other nodes that have discussions about performance and using the Benchmark module, this is just the last one I read that made me want to write this code.

There are 2 buttons, 4 text widgets in which to enter text, 1 text widget to show the output, and an adjuster.

  • Clear Button - clears all the text boxes and reset's the count to 1000.
  • Run Button - runs the tests using cmpthese from the Benchmark module. The output text widget will be cleared before the test is run, you can turn this off by commenting out the following line in the OnRun method:
    $tk{output_text}->delete(0.1, 'end');
  • count - this is the first argument to cmpthese.
  • test1 - this is the first snippet to be tested. An example:
    mapgen    => 'my @ones = mapgen 1, 1000;'
  • test2 - this is the second snippet to be tested. An example:
    xgen    => 'my @ones = xgen 1, 1000;'
  • code - this is where any supporting code should be typed; this field is not required. An example:
    sub mapgen    { return map $_[0], (1..$_[1]); }
    sub xgen    { return ($_[0]) x $_[1]; }
    
  • output - this is where the output from cmpthese will appear as well as the code that was eval'd. An example:
    COUNT=1000
    TEST CODE:
    {mapgen    => 'my @ones = mapgen 1, 1000;',
    xgen    => 'my @ones = xgen 1, 1000;',}
    SUPPORT CODE:
    sub mapgen    { return map $_[0], (1..$_[1]); }
    sub xgen    { return ($_[0]) x $_[1]; }
    
    RESULTS:
    Benchmark: timing 1000 iterations of mapgen, xgen...
        mapgen:  2 wallclock secs ( 2.14 usr +  0.00 sys =
      2.14 CPU) @ 466.64/s (n=1000)
          xgen:  1 wallclock secs ( 1.16 usr +  0.01 sys =
      1.17 CPU) @ 853.24/s (n=1000)
            Rate mapgen   xgen
    mapgen 467/s     --   -45%
    xgen   853/s    83%     --
    

Happy Benchmarking!

--
hiseldl
"Act better than you feel"

Storable 2 Text - An editor for data files created by Storable.pm
on Aug 08, 2002 at 13:57 UTC
by kingman
Opens a file created by Storable::lock_store and dumps the data structure to an ascii file for viewing/editing.

Also creates a file via Storable::lock_store that contains an empty hash if you create a symlink to the script called ts (touch store).

Mirror only the installable parts of CPAN
on Aug 08, 2002 at 06:10 UTC
by merlyn
As noted in a parallel thread, I have this short program which can mirror a complete set of the installable modules for use with CPAN.pm.

This is for review purposes only. A final version of this code will appear in my LM column. Comments are welcome.
WARNING: As stated, this was a preliminary version of this program for comment only. While writing the column, I fixed a few bugs. Do not use the version here. Use the version there instead.

diffsquid - find the differences in Squid configuration files
on Aug 07, 2002 at 15:06 UTC
by grinder

Analyse two squid configuration files, and report parameters that are present in one file but not in the other, or have different values. Also attempt to identify valid parameter names in the comments and report on those as well (useful when new versions are released).

rcmd.pl
on Jul 25, 2002 at 12:26 UTC
by greenFox
rcmd.pl -a utility for running the same command across a group of hosts.
dgrep - Wrapper around gnu find & grep
on Jul 22, 2002 at 20:10 UTC
by domm
I just cannot remember how to run find and grep together. After reading the FM once too often, I wrote this small wrapper..

Pass it a pseudo-regex (to match the files) and another one to look for in all files.

Example:
% dgrep .pm foo Will look for "foo" in all files ending in ".pm" in the current and lower directories.

Edited: ~Tue Jul 23 15:24:49 2002 (GMT), by footpad:
Added <code> tags to the code.

win2unix
on Jul 20, 2002 at 08:03 UTC
by ackohno
This is a little script i came up with to get those ^M's out of files that come in the downloaded source here at PerlMonks. Given one argument (a file name), the script removes the ^M's from that file; given two, the first is input and second is output. If the if statment matching for the perl shebang is removed, this script can be used to remove the ^M's from any file. Without that if statment, there may be a new line at the begining of the file witch will cause the script not to run.
CheckPoint rule auditor
on Jul 12, 2002 at 04:08 UTC
by semio
This script was designed to help me gain insight into rule utilization on the Check Point Firewalls I maintain e.g. rules most heavily used or, conversely, rules not being used at all. Its input is any semi-colon delimited file created using logexport on the Firewall. Works on 4.1 and NG
backfiles
on Jun 27, 2002 at 03:23 UTC
by xiphias
Backs up files using tar into dirs in backlist.txt. Quite simple
MODULATOR
on Jun 21, 2002 at 01:39 UTC
by epoptai
Browse pod and code of installed perl modules in a handy frameset. Lists each installed perl module linked to an HTML rendering of its pod if any, and to its source code. Option to automatically put synopsis code into a form for easy testing via eval (this is both powerful and dangerous, use caution). Lists environment variables and result of various path and url finding methods. Here's a screenshot.

Updates:

  • fixed problem with "refresh cache" not refreshing the cache.
  • added "no header" option to code eval, for testing output of modules like GD.
  • implemented this fix suggested by perigeeV.
  • added a link to the perl module list.
  • added function to list module source code with numbered lines.
  • Added a CPAN search form.
  • nnml2mbox
    on Jun 11, 2002 at 15:45 UTC
    by mikeirw

    I needed to view the contents of a nnml mail directory, but didn't have access to Emacs or Gnus, so I whipped up this simple script to allow me to use mail -f instead. I must say that I'm a Perl newbie, so it may need some work. If so, I'll appreciate any comments.

    A quick note: I did not include any code to match Gcc'ed emails (which doesn't generate a From header), so you may need to add that before running.

    Statistical data analysis
    on Jun 05, 2002 at 12:56 UTC
    by moxliukas
    This short program outputs some statistical analysis data given the input data in two tab separated columns, first one being X column, and the second one Y column. It calculates means, quartiles, median, variance and standard deviation for both sets of data. It also outputs various sumations (X, X^2, Y, Y^2 and X*Y). It then calculates covariance, linear correlaton coeficient and determinance and finally comes up with linear regression equation.
    Most of this is simple and straightforward maths and I do hope it will prove useful to someone (well, I have used this script for my statistics lectures).
    Fake daemon
    on May 30, 2002 at 02:31 UTC
    by hagus
    A script I dug out of my archives. I submit it here in the hope that someone might find some useful sample techniques, despite its hurried appearance. I wrote it awhile ago with the following goals:

  • To make a non-daemon process run as if it were a daemon (ie. give it a controlling terminal).
  • To collect the stderr and stdout streams from that process uninterleaved (is that a word?).
  • To restart the process at a particular time each day.
  • To restart the process should it die unexpectantly.

    Things needing fixing that I can see:

  • Signal handling is below par. I don't understand it very well, as I seldom have to handle signals in perl.
  • Restart time is hardcoded - it really should take either a maximum run-time argument, or a date string which is parsed.
  • Command line arguments, anyone?
  • Handling infinite loops when restarting the process. Ie. if restart occurs more than x times in y seconds, sleep for z or exit.
  • Other stylistic or design problems people might see?

  • MySQL backup
    on May 24, 2002 at 23:25 UTC
    by penguinfuz
    This script backs up each MySQL database into individual gzip'd files; Useful in shared environments where many users have their own MySQL databases and wish to have daily backups of their own data.

    UPDATE: 17/07/2003
    • Now using bzip2 for better compression
    • Removed connect() subroutine
    TODO
    • Read db owners from a config file and automatically deliver backups to the appropriate ~user dir.
    Service Health Scanner
    on May 19, 2002 at 11:23 UTC
    by penguinfuz
    Basically the script first tries to resolve the domain name, if it failes you get email notification telling you which domain could not be resolved. If the domain resolves ok, the domain is then scanned for whatever service is specified, if this fails you recieve a notification of which domain is having trouble.

    The subject line of the email notifications have been tailored for output to a mobile telephone and/or pager.

    UPDATE: Complete rewrite, still checking for DNS resolution before moving forward, but now using LWP::Simple to check web/SSL connectivity, and email notifications are more user-friendly in that the failed service and hostname is listed in the SOS.
    NFS Watcher
    on May 16, 2002 at 13:13 UTC
    by penguinfuz
    I wrote this script to address an issue I had with Apache authentication and multiple load-balanced web servers, and I run it from a cronjob every so often.

    Basically I keep ONE copy of the relevent .htaccess files and NFS export their location to the other web servers in the cluster.

    I am sure this script could be extended further, but I have not messed with it since it serves the basic purpose I started towards. I hope someone else will find this code useful as well. ;)

    UPDATE:
    Added "use strict;" and found a missing semicolon at: my $ip_add = "192.168.0.10"
    And a global @mntargs; hanging around.
    gdynfont.pl - A Gimp plug_in
    on May 13, 2002 at 21:17 UTC
    by simonflk
    This plugin will display information about a GDynText layer in the Gimp.

    Background
    I needed to find out the name of the font that I used in a .XCF a few months ago. I didn't have the font installed anymore, so GDynText selected the first font in the list. It may be that I have overlooked a simpler way of working out the font, nevertheless, this was a nice excursion into Gimp-Perl. Unless you are in a similar situation (no longer have a font, or someone gives you a Gimp file without associated fonts), this will be pretty useless because it doesn't display anything that you can't get from GDynText itself.

    Installation
    Copy this script into your ~/.gimp-1.2/plug-ins folder and make it executable.

    Usage:
    Select a GDynText layer and then select GDynFontInfo from the <Image>/Script-fu/Utils menu
    dfmon - Disk Free Monitor
    on May 09, 2002 at 12:04 UTC
    by rob_au
    This little script is a rewrite of a very nasty bash script that for a long time formed a core crontab entry on systems which I administer. This code allows for the alerting of the system administrator via email when the disk space on any of the mounted partitions drops below a set threshold.

    The corresponding template file used for the email sent to the system administrator may look similar to the following:

    This is an automatically generated message. The following file systems have reached a storage capacity greater than the alert threshold set within the dfmon.perl administrative script. [% FOREACH fs = filesystems %] [% FILTER format('%-10s') %][% fs.mountpoint %][% END -%] [%- FILTER format('%15s') %][% fs.blocks_total %][% END -%] [%- FILTER format('%10s') %][% fs.blocks_used %][% END -%] [%- FILTER format('%10s') %][% fs.blocks_free %][% END -%] [%- FILTER format('%5s%%') %][% fs.percent %][% END -%] [%- END %] --

     

    VBA 2 Perl
    on May 08, 2002 at 18:37 UTC
    by Mr. Muskrat

    vba2pl reads a VBA macro file and attempts to translate the contents to perl. It outputs to a file with the same path and base name but a .pl extension.

    It's far from finished although it has come a long way since I started on it last night.

    It got its start in my follow up to Win32 - M$ Outlook and Perl.

    Mandatory "Dark Side" quotes...
    "If you only knew the power of the Dark Side of the Force" - Darth Vader
    "Once you start down the Dark Path, forever will it dominate your destiny, consume you it will..." - Yoda

    SSManager
    on May 05, 2002 at 22:01 UTC
    by Anonymous Monk
    This module wraps a number of SourceSafe OLE Server functions in one-step function calls.
    Duplicate file bounty hunter
    on Apr 24, 2002 at 00:42 UTC
    by djw
    This will search out a directory recursively for duplicate files of a specified size (default: 100 MB). It logs everything and makes you dinner.

    Enjoy, djw

    *update* 04.24.2002
    After some suggestions by fellow monks, I have changed this to use Digest::MD5. Thanks everyone++.

    djw
    Summarize Orange phone bill
    on Apr 03, 2002 at 09:21 UTC
    by fundflow
    Parse the phone bill given by Orange cellphone company (www.orange.net)

    It shows the information per phone number (number of calls and text messages, and the cost/minute). I use it to check which of my friends costs me the most :)

    I'm now in the UK and this is the bill they give here, but this might work in other countries. In case there's a problem with other countries, let me know.

    Oracle DB & Server Backup
    on Mar 29, 2002 at 02:42 UTC
    by samgold
    Script to backup 4 Oracle databases and then backup the
    server using ufsdump. It backs up 2 databases a day and
    then the other 2 the next day. This was written for a
    Sun Box backing up to a DLT tape drive. Look for
    places where lines will need to be edited noted by #!!
    If you have questions or comments please let me know.
    Length
    on Mar 14, 2002 at 07:46 UTC
    by Juerd
    This code is very simple, and I think every experienced Perl coder can think of it. However, I use this twice a day, so it's useful to me. It might help out others, or at least make some of you toss away those old while(1) { print length(<>) - 1, "\n" } scripts that some people have.
    tree.pl - kinda like tree
    on Mar 04, 2002 at 20:42 UTC
    by crazyinsomniac
    heard of the Perl Power Tools, well this one was a missing one (tree). This version builds a LoL, with the first element in each list being the directory name. Output of the real tree utility looks like
    F:\DEV\FILE_TREE\B
    |   file
    |
    \---c
        |   file
        |
        \---d
                file
    Improvements are welcome.
    (code) Ignore The Man Behind The system(rsync) Curtain
    on Mar 01, 2002 at 03:33 UTC
    by ybiC

    Wrapper for rsync, intended for backing up data betwixt a client (Cygwin on Win32|Linux) and a server (Linux).

    I looked into File::Rsync module, but it also employs 'exec' calls.   So for now will stick with system call to rsync, for simplicity and for standard-distribution- modules only.

    From a Perlish standpoint, this has been a refresher in the use of 'tee' (props to tye and Zaxo), another chance to use the nifty Getopt::Long and swell Pod::Usage modules, use timestamps for logfile names, detect OS type with $^O, use the keen-o filetest operators, sprintf for human-readable date+time, and to write another silly Perl script that's 50% pod.

    As always, comments and criticism are wildly welcomed.

    Update:
    Experimenting with File::Rsync to ease parsing-on-Cygwin woes.
    Add parsing code by Zaxo
    Minor tweaks to pod
    Present runtime in appropriate units (sec, min, hour...)
    Handle backups of rsync modules *to* rsync server in addition to *from*


    Searching for 'chunks' of data in very large files
    on Feb 28, 2002 at 18:21 UTC
    by Ovid

    Recently, in the Perl beginners list, someone had a bit of a quandary. They were reading a 600 MB file and needed to find a search term, grab from the file 200 bytes of data both before and after this term and then search for another term within that 'chunk' of data.

    I thought this was such a fun problem that I went ahead and wrote the program for this person (yeah, I know, I gave him a fish). This is deliberately overcommented in case the person did not know a lot of Perl. The basic idea is to search the file and return 400 byte 'chunks' in an array.

    Virus Tester
    on Feb 24, 2002 at 04:40 UTC
    by ProgrammingAce
    This little perl script will see if your antivirus software is paying attention by writing a file called aseicar.com to your C: drive. This file contains a small string that is harmless. Your antivirus program should register the new file as the "Test-String Virus". I repeat, THIS FILE IS HARMLESS!
    flexible find
    on Jan 27, 2002 at 17:17 UTC
    by axelrose
    Here is a little script I always wanted to have: a "find" script which
    • - runs on Macs (and *nix, Windows too)
    • - creates objects while running
    • - has an understandable "-prune" option
    • - uses Perl regex for filtering
    This should make it easy to extend the idea for your purpose. The example below outputs found files sorted by modification time. You can change it to list directories sorted by size or by mtime by providing a directory callback function:
    my $dirfunc = sub { push @dirs, File->new( name => $_[0] };
    WalkTree::walktree( $mystartdir, undef, $dirfunc, undef );


    I'm happy about your comments. Best regards, Axel.
    mrtg.errorcap - reformat MRTG errors
    on Jan 25, 2002 at 16:36 UTC
    by grinder

    When running MRTG from cron, if a device fails to reply within the allotted time, iit spits out a voluminous error message. If many devices are down (because a nearby gateway has fallen off the net), the exact nature of the problem can be difficult to see, as there is too much output to wade through.

    This script takes the output, reformats and summarises it and sends it to the relevant authorities.

    Regex Checker
    on Jan 08, 2002 at 18:45 UTC
    by mrbbking

    2002-01-09 Update: Note to Posterity - there are better ways than this.
    After posting this little thing (which truly was helpful for some), two fine folks were kind enough to point out a better way of understanding your regex and a fine online reference - neither of which I had managed to locate on my own.
    Many thanks to japhy for creating them and to tilly and crazyinsomniac for pointing them out.
    If you're here looking to learn more about regular expressions, you'll do well to follow those links.


    A new guy here was confused by the difference between "capturing" with parens and "grouping" with brackets. I gave him this function to help show the difference, but it's useful for general testing of regular expressions.

    The thing to remember is that it's easier to write a regex that matches what you're looking for than it is to write one that also doesn't match what you're not looking for.

    Note: I did not use the 'quote regex' qr//; because that makes print display the regex in a way that differs from what the user typed. My goal here is clarity.

    Further Reading (in increasing order of difficulty):

    PingSweep
    on Jan 04, 2002 at 03:08 UTC
    by sifukurt
    I've been working a lot with Perl/Tk recently (mostly just for fun), and I needed a script that would verify that a list of servers were active. So I combined the two things and ended up with PingSweep. It reads the servers out of an XML file (default name of the XML file is "hostdata.xml"), and the specifications for the XML file are included in the help text. It defaults to pinging the servers 20 times every 90 seconds, and sends an email to a specified address if any of the servers fail to respond. All of those options can be modified from the command line via Getopt::Long.

    Hopefully you'll find it useful. As always, feedback is welcome.
    (Fake) CVS Import Utility
    on Dec 18, 2001 at 05:26 UTC
    by vladb
    Does exactly what a 'cvs import' command would do with the only exception that a version of working source files will not be generated inside an active CVS repository. For that matter, it also doesn't require you to execute the 'cvs checkout' command to retreave source code from the repository to start working on. This, in turn, means that you may start archiving versions of your current source files immediately after running this script inside the directory containing those source files.
    Verify Your FreeBSD CD
    on Dec 10, 2001 at 14:36 UTC
    by crazyinsomniac
    If you just downloaded 4.4-install.iso also known as FreeBSD 4.4 ISO, and you "burned" it to a cd, and you wish to make sure that all the packages contained are as they should be (Debian has been really lame about this, I had at least 5 packages fail, even tough the "burn" was good, it turns out, just a shabby iso release)
    perl verify_freebsd.pl -d D:/>burnt
    WHAT?!?!: For some reason, in \XF86336\CHECKSUM.MD5 the line MD5 (Servers) = edc0aef739c1907144838e6c18587e02 which apparently is the md5 sum for the "directory" \XF86336\Servers which you might be able to do in *nix, but on on winblow.
    Verify Your Debian Potatoe
    on Dec 09, 2001 at 16:04 UTC
    by crazyinsomniac
    All your smurf are to "Verify Your Debian Potatoe" after baking smurf .iso

    perl verify_potatoe.pl -d D:/>burnt
    update: if you run accross "d41d8cd98f00b204e9800998ecf8427e" you've got yourself an empty file. Beware, some cd-r's play mind games
    CSV Database Validation
    on Nov 19, 2001 at 09:20 UTC
    by Ovid

    Recently, for a personal project, I was using DBD::CSV to create a simple database. I was dismayed how little validation there was. The following program will allow you to create a CSV database and validate unique fields, foreign key constraints, and simple data types. You can also use this to validate data against regular expressions. Naturally, these are one-time validations.

    Also included is support for validating an existing CSV database or CSV file. See POD for complete details.

    Please let me know if you find any bugs in this code. Also, a code review would be appreciated :)

    logrotate
    on Nov 12, 2001 at 19:23 UTC
    by enaco
    This is a script for rotating logs.
    It reads a configuration file that tells it what files to rotate, how long the rotate history is and if it exists, what program to send a HUP when rotatings its log.
    This script was made primarly for learning perl but still a usefull pice of work.

    The script is not quite done yet, i still got some bugs to fix, i release it early and hope for some input.

    spew - print out random characters
    on Nov 12, 2001 at 19:19 UTC
    by grinder
    Print out random characters, suitable for making hard-to-guess password, or manual IPSec authentification keys (which is why I wrote this in the first place).
    Obscure
    on Oct 25, 2001 at 20:14 UTC
    by JimE
    While contrary to the spirit of Perl, the harsh realities of the world sometimes make it desireable for your code to be less than totally open. Although it gets discussed from time to time in various forums, I've never actually found a tool to do this, so I wrote a 'perl code obscurer' for my current need that might be of some use to others. Does not go as far as the encrypt/decrypt model proposed by some, just file munging and var renaming to produce a distributable file that the interpreter can run. Discourages tampering but won't stop a determined reverse engineerer. More details in the pod in the file...
    makeperl
    on Oct 17, 2001 at 21:47 UTC
    by Rich36
    A very simple script, but one that I use all the time. I find myself writing a lot of small Perl scripts and I find this to be a convenient method for getting started, saving a little time, and imposing a standard coding structure.

    makeperl creates a new file, writes a standard format/template for a Perl script, changes the permissions to be executable, and opens the file in an editor.

    I also use this a lot for when I'm trying out code examples from books, online, etc.

    This has only been successfully tested on *nix, but should work elsewhere.

    snapdiff -- Compare CPAN autobundle files
    on Oct 16, 2001 at 23:03 UTC
    by Fletch
    CPAN.pm can create a bundle file which contains all of the modules which are currently installed on a box with its autobundle command. This program will compare two such snapshot files against each other, noting what modules are in the first but not in the second (and vice versa) as well as if there are differing versions of the same module. Handy if you're trying to duplicate the configuration of one box on another, or want to see what's changed over time if you keep historical bundles.
    Dump.pl
    on Oct 03, 2001 at 06:42 UTC
    by hsmyers
    Nothing fancy, just a straight forward binary dump of a file in a formatted display to either STDOUT or filename. Particularly handy to compare what you think is in the file with what is actually in the file!

    hsm

    Simple Directory Mirror
    on Aug 31, 2001 at 21:59 UTC
    by sifukurt
    This is a quickie script I wrote to backup files in my work directory to a backup directory. I thought it was handy, so I thought I'd post it here.
    Linux message log webifier
    on Aug 31, 2001 at 08:33 UTC
    by hans_moleman

    This is a script I threw together to provide a web version of the Linux message log, indexed by service name. I'm a new perl coder so comments and especially suggestions would be much appreciated...

    NOTE: This code has been modified as a result of the helpful suggestions given to me... ;)

    09/02/2001 - heavier modifications now, I have put the file write stuff into a sub where it belongs and added code to read the logfile both by service and by date. By the way, this script should work for any syslog type log, I have tried it on /var/log/secure and it works like a charm...

    09/03/2001 - added variables for HTML colour settings, kind of a poor man's style sheet ;).

    GetUsers
    on Aug 30, 2001 at 23:15 UTC
    by Jerry
    Client app for my GiveUsers server. Currently set up to get the password and shadow files (gpg encrypted before crossing the network!!), and changing all shells to /bin/false (except the first 20 lines). Be sure to create GPG keys and import them to the other box (as the user which will be running the GetUsers and GiveUsers scripts)
    Regex Tester
    on Aug 21, 2001 at 20:28 UTC
    by George_Sherston
    A cgi that lets you try out regular expressions and see the results in an ergonomic way. No rocket science, but a thing I, who am fairly new to regexes, have found very useful for learning how they work, and coming up with the right one to do what I want. Some people can work it all out in their heads - I find trial and error indispensable!

    The code is below, in case anybody wants to put it on his or her own machine, or check to make sure it's doing what it says on the box. But if you just want to use it, then please feel free to click here

    George Sherston

    PS - Alright already, I know all my variables are global and I didn't use straitjacket ... it's For Home Use!
    PPS - Having said that, I would, of course, welcome style comments and suggestions for how to make it slicker. Every day and in every way I am getting better and better.
    NotSoLong.pl
    on Aug 12, 2001 at 03:53 UTC
    by ichimunki
    Code::Police
    on Aug 01, 2001 at 19:41 UTC
    by Ovid

    This is the Code::Police module. Provide this module to programmers who fail to use strict and most of their coding errors will be instantly eliminated.

    cols2lines.pl
    on Jul 31, 2001 at 19:41 UTC
    by tfrayner
    Time once again to reinvent the wheel, I suspect. I wrote this a couple of years back as an exercise in perl. Specifically, a friend of mine was wanting to manipulate large (>10GB) tables of data. Part of his analysis involved transposing a table such that the columns became lines and vice versa. As a result I wrote this rather convoluted script. It only loads one line of the table into memory at a time, rather than the whole table.

    The other points of this exercise were to make the code as well-structured (whatever that means :-P) and as user-friendly as possible. I imagine it's possible to load the essential functionality into a single line, but that wasn't my aim here.

    Of course, I imagine there's a perfectly good CPAN module out there which would do this much better than this :-)

    Update: The original script opened and closed the input file with each column that it read. I've changed to the more efficient seek function suggested by RhetTbull.

    Perl Code Colorizer
    on Jul 31, 2001 at 11:29 UTC
    by BrentDax
    Okay, this one is pretty scary. This script reads in a (simple) chunk of Perl code (using normal filter behavior) and spits out an HTML file with certain things colorized. (You can see the list in the setup of the %config hash at the top.) It's extremely regexp-heavy. It's also pretty easy to confuse.

    Notable bugs:
    1. In a line like m#regexp#;  #comment, the comment won't be colorized. Sorry.
    2. In a line like m{foo{1,2}bar}, the program will get confused and stop highlighting after the 2. I've really got to work on nesting...

    For all that, however, there's a lot of cool things it /can/ do, like:
    -recognizing and colorizing (most) heredocs
    -colorizing statements like @{&{$foo{bar}}} nicely to show which curlies belong to which sigil
    -actually working most of the time

    Only the colors for sigils are well-thought-out--the rest were just temporary values I assigned on a whim.

    Also note that this was a lot of monkeys and typewriters--I myself aren't quite sure how it all works correctly. Well, have fun with this chunk of code!

    Perl port of locate
    on Jul 19, 2001 at 18:41 UTC
    by sifukurt
    Personally, on a Linux system, I use locate very regularly. The problem is that I have a couple Win32 systems that I use, and, of course, there isn't a tool like locate. So I wrote this. I use it quite a bit, so I thought I'd share it here in the hopes that others would find it useful. I tried to be as compliant with the GNU locate command as possible, plus I added a few simple features that I needed but weren't part of the GNU locate specifications.

    There are a few variables that you'll want to alter to suit the needs of your system. Comments welcome.
    Generic Password Generator
    on Jun 28, 2001 at 15:35 UTC
    by claree0
    A simple (i.e. easily adapted by those with more specific requirements) password generator, which will generate passwords according to a template. Useful for environments where the use of a specific format of password is encouraged.
    nugid - new user/group ids
    on Jun 25, 2001 at 13:28 UTC
    by grinder

    When you have a large host with hundreds of users, managing file ownerships becomes hard. People come and go, but their files remain, and these files have to assigned to other users. By itself the chown(1) program is too severe, as it will operate on anything it can get its hands on. This can be very disruptive in a directory tree where files may be owned by dozens of individuals.

    So I wrote a script that is a little more selective, in its own words, it will

    Selectively modify user and group ownerships of files and directories depending on current ownerships. All files that match the given group id or user id will be changed to the new specified id. Numeric and symbolic ids are recognised.

    Comments, suggestions and criticisms welcomed. I think the script name sucks, but I can't think of a better one.

    Directory Tree Comparison Module (File::DiffTree)
    on Jun 23, 2001 at 00:23 UTC
    by bikeNomad
    This is a package that I wrote after seeing some other scripts here that did similar things. This package allows the behavior on same/different files as well as comparison to be pluggable using CODE references. It may become a CPAN module if the response here is positive enough. An example program that uses it is at the end.
    Password Manager
    on Jun 12, 2001 at 18:12 UTC
    by DaveRoberts
    A simple Tk solution to allow simple management and change of NT and Unix passwords. Designed to make management of many accounts (and passwords) a little easier. This does not remember your passwords (yet) but provides a single interface that allows passwords to be managed.
    macls
    on Jun 06, 2001 at 22:00 UTC
    by snafu

    Rev ver 1.0:
    This script is intended to get the mtime, atime, ctime information from a file or a list of files in a given directory. This is helpful to do basic file security auditing on your system. Read the comments in the script to get usage.

    Updates:
    Rev ver 2.1

  • Added locale tz tweak.
  • Added symbolic permissions modes to output. Many thanks to pwalker@pwccanada.com @ http://php.ca/manual/ru/function.fileperms.php. He doesn't know he helped but his code was invaluable to the symbolic mode code I added to this script.
  • Finally made a few changes that were suggested from Jeffa. Made other minor (beautification) changes.
  • General clean up.
  • Syntax changes that I felt made the script easier to read and more maintainable. Added GPL comments at top with (c) 2001. Subversion tags added for info only.
  • If there are tweaks performed on the script I would sincerely appreciate an email with a copy of the script with your changes.

    Tested successfully on: Linux, Solaris, FreeBSD

    Comments would be appreciated.

    (code) Yet Another Gzip Tarball Script
    on Jun 04, 2001 at 03:38 UTC
    by ybiC
    I wrote this ditty to automate file copies, while retaining last-modified timestamps.
    1. Backup system configs, web directories, and perl scripts on 4 computers.
    2. Make it easy to keep perl scripts synchronized across the same 4 PCs.

    Create gzipped tarball of all files in specified directories.   Status and error messages written to console and logfile.   Selectable compression level, recursion(y/n), log and dest files via commandline switches.   Tested with Perl5.00503/Debian2.2r3, ActivePerl5.6/Win2k, Perl5.6.1/Cygwin/Win2k.

    Sample run logfile at tail of pod.   Critique, corrections and comments wildly welcomed.

    Thanks to Vynce, mlong, bikeNomad, zdog, Beatnik, clintp, Petruchio and DrZaius for suggestions, tips and pointers.   Oh yeah, and some guy named vroom, too.

    Latest updates   2001-06-05 14:25 CDT

    Correction:
    Our very own bikeNomad wrote Archive::Zip, not Archive::Tar.

    Perl Tags generator
    on May 25, 2001 at 23:19 UTC
    by bikeNomad
    Perl editor tags generator (like ctags) that uses the debugger hooks to avoid parsing Perl itself.

    update: avoid getting into long loops when the line number happens to be 65535 because of (apparently) a Perl bug

    Work Backup
    on May 16, 2001 at 01:26 UTC
    by John M. Dlugosz
    This is a Perl program to perform daily backups of interesting "work" files in an intelligent manner. Developed under Win32, should be OK on all platforms.
    JournalH.pl
    on May 15, 2001 at 21:54 UTC
    by JSchmitz
    Journal maker for the lazy - more time to drink Whoop-ass and listen to Slayer.
    Unlinker.pl
    on May 15, 2001 at 00:03 UTC
    by JSchmitz
    Uses Perl's unlink to auto-delete numerically named files. Needed this here at work.
    ping for ppt
    on Apr 23, 2001 at 00:29 UTC
    by idnopheq
    ping -- send ICMP ECHO_REQUEST packets to network hosts

    ping tests whether a remote host can be reached from your computer. This simple function is extremely useful as the first step in testing network connections, ping sends a packet to the destination host with a timestamp. The destination host sends the packet back. ping calculates the time difference and displays the data.

    This test is independent of any application in which the original problem may have been detected. ping allows you to determine whether further testing should be directed toward the network connection or the application. If ping shows that packets can travel to the remote system and back, the isse may be application related. If packets can't make the round trip, the network may be at fault. Test further.

    Added actual ~pinging~ sound via the system bell, per the cononical naval usage of the term and the jargon file's entry (see the -a -A options).

    The funniest use of `ping' to date was described in January 1991 by Steve Hayman on the Usenet group comp.sys.next. He was trying to isolate a faulty cable segment on a TCP/IP Ethernet hooked up to a NeXT machine, and got tired of having to run back to his console after each cabling tweak to see if the ping packets were getting through. So he used the sound-recording feature on the NeXT, then wrote a script that repeatedly invoked `ping(8)', listened for an echo, and played back the recording on each returned packet. Result? A program that caused the machine to repeat, over and over, "Ping ... ping ... ping ..." as long as the network was up. He turned the volume to maximum, ferreted through the building with one ear cocked, and found a faulty tee connector in no time.

    Requires up-to-date Net::Ping and Time::HiRes. Many thanks to Abigail's neat warn and die subs from the http://language.perl.com/ppt site!

    Two items anyone can help with:

    • Sig{INT} control for Win32 - Term::ReadKey (which I could not get to work right for this one script)?
    • TTL on various systems, like Win32. I know the default from the RFC, but the reallity and how to automagically query?

    UPDATE: ACK! I posted an old version w/o the ping sound! Here it is.

    UPDATE 1: submitted to PPT for inclusion

    md5sum for PPT
    on Apr 13, 2001 at 01:35 UTC
    by idnopheq
    md5sum computes a 128-bit checksum (or fingerprint or message-digest) for each specified file. If a file is specified as `-' or if no files are given md5sum computes the checksum for the standard input. md5sum can also determine whether a file and checksum are consistent.

    For each file, `md5sum' outputs the MD5 checksum, a flag indicating a binary or text input file, and the filename. If file is omitted or specified as `-', standard input is read.

    I added functionallity from BSD md5 and some other md5sum ports (MS-DOS, etc.) for compatibility. FSF md5sum is the default.

    TAR.pl
    on Apr 11, 2001 at 20:06 UTC
    by $code or die
    I wanted to find a simple command line TAR\GZ program for Windows to GZip my modules for uploading to CPAN. But I couldn't find one I liked.

    Of course there is always cygwin which I urge everyone to download who use "explorer.exe" as a shell. It's only a small download.

    However, this fitted my needs. Please let me know any comments or improvements.

    Update: You might also want to check out btrott's script which does the same thing but also stores the path. I didn't see this before I posted mine.
    Gantt Diagrams
    on Apr 02, 2001 at 10:56 UTC
    by larsen
    Simple module to produce Gantt diagram from XML project descriptions.
    Or, what Perl can do to help you if you're planning to conquer the world?.
    detect sneaky processes which modify their process name.
    on Mar 26, 2001 at 06:11 UTC
    by rpc
    This script walks through each PID in /proc and performs several checks to determine whether or not a process has modified its process name. It's trivial for a program to mung its process name and fool utilities such as 'ps'. There's many malicious tools available which try to hide their pressence, using more common process names like 'pine'. However, if the binary itself was not invoked with this name, it's possible to detect using the /proc interface.
    pinger - ping a range of hosts
    on Mar 23, 2001 at 19:19 UTC
    by grinder
    A little script that provides an easy way of pinging all the hosts from, e.g. 192.168.0.1 to 192.168.0.100. The output can be tailored in various ways.
    vargrep
    on Mar 13, 2001 at 01:21 UTC
    by japhy
    A raw attempt at scanning a Perl program for specific variables. Results are usually good.
    Week Partitioner
    on Mar 09, 2001 at 02:02 UTC
    by japhy
    This program takes a month and a year, and returns output like cal, for the days of the month between Monday and Friday.
    chmug
    on Mar 07, 2001 at 04:01 UTC
    by tye
    A perl-only replacement for chmod, chown, and chgrp that I found very convenient when I was a Unix sys admin. It lets you change the mode, owning user, and owning group all at once (or any combinations thereof).

    This is some pretty old code (last updated in 1995) but it doesn't look horrendous so I thought I'd add it to the archive.

    Tcl/Tk to Perl Tk
    on Feb 27, 2001 at 06:06 UTC
    by strredwolf
    A rather crude converter, but if you design it with wish, and then change it over, cuts things down a bit.
    Find and convert all pod to html
    on Jan 30, 2001 at 01:33 UTC
    by ryddler
    Searches the site and lib directories on an ActiveState install for any POD that isn't in HTML format and converts it. Rebuilds HTML TOC after conversion. A logfile is kept to track additions.
    shrink.pl - Scales down images
    on Jan 21, 2001 at 23:28 UTC
    by Vortacist
    This is my first major perlscript (with help from Falkkin)--it scales down the size of images in a specified directory and all of its subdirectories. This is not a compression algorithm--it simply resizes the images based on command-line options. The user may specify size (as "xx%" or a number of pixels), starting directory, and which types of image files to resize. The user is required to specify a size; if none is given, the online help message is printed. Please see this message for more info.

    I tend to do a lot of image-resizing for CD-ROM scrapbooks and thumbnails and thought other people might find this script useful for similar tasks.

    I would appreciate any suggestions on how to make this script more efficient, and I'd also like to know if the help text is clear enough. Thanks!

    Update: Changed code as per merlyn's suggestion below, with one slight difference (see my reply).

    csv2png.pl - Line Graphs from a CSV file
    on Feb 16, 2001 at 23:14 UTC
    by clemburg
    This is a small script that takes CSV data as input and generates a PNG file displaying a line graph as output. Basically, each column in the CSV file is a data series that will be displayed as a line graph. The first series labels the X axis.
    (self-deprecated) slack updater
    on Jan 12, 2001 at 05:22 UTC
    by mwp

    Deprecated: If you're looking for a script to do this for you, I highly recommend autoslack, written by David Cantrell (of the Slackware Team). It can be found in the unsupported directory on any slackware mirror.

    A relatively simple script that I'm writing which scans a local, uninstalled copy of Slackware 7.1 and updates the packages from a slackware-current mirror. Very rough around the edges, so be gentle. Gives you the option of installing downloaded packages but is not integrated with /var/adm/packages info in this version. Useful to a point, mostly written for myself only because Patrick Volkerdeing & Co. are writing a script named 'autoslack' (in Perl!) with the same exact functionality, 'cept probably better! I was just impatient.

    Good example of Digest::MD5, following our recent discussions!

    Sun Fingerprint
    on Jan 05, 2001 at 08:37 UTC
    by a
    Uses Sun's on-line md5 database to validate your Solaris system files (exe and libs). As in, checking for trojans or just getting the proper version numbers. You could run it in a pipe yibC w/ find or ls, e.g.
    ls /bin | sunfingerprint - has various levels of output (even the whole, original html) so you could do various things to see what it complains/notices.
    mkpkg
    on Jan 03, 2001 at 19:25 UTC
    by kschwab
    A wrapper script for pkgmk on Solaris to create Solaris software packages. (pkgmk and pkgtrans are overly complicated...this simplifies things for me)
    switcher
    on Dec 31, 2000 at 01:18 UTC
    by $CBAS
    woohoo! my first code on PM! :-)
    This little thing sweeps through directories to change the extensions of files (I use it to rename .MP3 files to .mp3 ... damn AltoMP3!)
    tidyhome
    on Dec 17, 2000 at 01:02 UTC
    by billysara
    A little script to tidy users home areas by moving files from ~/ to subdirectories related to filetype. Written so I didn't need to spend my time tidying up all those .tar.gz files I accumulate from freshmeat...
    col for PPT
    on Nov 30, 2000 at 04:06 UTC
    by chipmunk

    This script is a Perl implementation of the Unix col utility, which filters reverse line feeds from input. (More details: col manpage) It was written for the Perl Power Tools project. Sadly, the PPT webpages have not been updated since I submitted this script. So, I'm posting it here, because I don't want the script to go to waste.

    When I wrote this script, I had access to two different implementations of col, one on BSD and the other on IRIX. I added new command-line options so that, in most cases where the BSD and IRIX implementations behaved differently, my own implementation could be instructed to emulate either.

    Although there are no known bugs in the script, there may be bugs that I am not aware of. Please let me me know if you find any. Comments and suggestions are welcome as well.

    P.S. Also, if anyone has a use for this script, please let me know. I'd never even heard of col until I saw it listed in the PPT!

    onlyone
    on Oct 31, 2000 at 01:58 UTC
    by BoredByPolitics

    This is my second perl program, written to fulfill a need at work. I was wondering if someone with more experience could critique it, there being no other perl programmers in my office :-)

    It's aim is to be run as part of the .bash_profile, to remove any prior D3 program running from the user's IP, to solve the problem of rebooted clients at a customer of ours (stopping them rebooting wasn't an option).

    Oh, almost forgot, it's also supposed to run suid root, as the users often use different login names from the same workstation.

    Find Duplicate Files
    on Jan 04, 2001 at 23:08 UTC
    by salvadors
    As my original Find Duplicate Files script was so popular I decided to take the advice of turning it into a module. Here's the initial verison of it. I'd appreciate feedback on ways to provide a nicer, more useful, interface than just returning a HoL.

    Thanks,

    Tony

    PMail
    on Oct 02, 2000 at 17:47 UTC
    by le
    This script takes a Unix Mailbox (in so-called Berkeley format), and generates several HTML files from it. (Just as many Mail-to-HTML programs do.)

    The output looks almost like the one from hypermail.

    Yeah, I know, you might say "Come on, this is mail2web no. 2365, who needs it?"... well I just did it for learning purposes. Maybe you can learn, too.
    syscheck: check system files for changes
    on Sep 11, 2000 at 02:05 UTC
    by cianoz
    this program checks files and directories in your system reporting if they were modified (by checking an md5 sum) created or deleted since last time you initialized it.

    I use it to check my /etc /sbin /lib /bin /usr/bin and /usr/sbin for changes i didn't made (backdoors?)

    you can run it from a cron job or manually (it is safe to store a copy of the checksum database outside the system) it takes about 2 minutes to scan all rilevant files on my systems.

    although it seems to work for me it is just a quick hack, i would appreciate some hints to make it better.

    expirescore.pl
    on Sep 02, 2000 at 02:29 UTC
    by le
    I use the slrn newsreader and my scorefile got to big (it was over 2 MB), with a lot of old scores, because I didn't set expiration times for the scores, so I hacked this script, that reads in the scorefile and lets me expire scores (based on Time::ParseDate features like older than "5 days", "3 months", "2 years"), and writes back the scorefile.

    Currently, it only runs interactive, but maybe I (or you) will add the needed features to run without user interaction (e.g. for cron scripting).

    Pathfinder - find duplicate (shadowed) programs in your PATH
    on Aug 26, 2000 at 09:12 UTC
    by merlyn
    Run this program (no arguments) and see which items in your PATH environment setting are shadowing later programs of the same name. This is an indication that you might get failures running the scripts of others, or perhaps if you ever rearrange your PATH.
    Find out where symlinks point
    on Aug 09, 2000 at 15:31 UTC
    by merlyn
    Walks through one or more directories specified on command line, and fully expands any symbolic links within those directories to their real locations, taking into consideration all the relative and absolute symlinks that occur, recursively. Originally written for a Performance Computing/SysAdmin magazine Perl column. Go see there for a line by line description.
    wanka
    on Aug 08, 2000 at 23:57 UTC
    by turnstep

    Just a simple hex editor-type program. I actually wrote this back in 1996, so go easy on it! :) I cleaned it up a little to make it strict-compliant, but other than that, it is pretty much the same. I used it a lot when I was learning about how gif files are contructed. Good for looking at files byte by byte.

    I have no idea why it was named wanka but it has stuck. :)

    What's eating all your disk space?
    on Jul 12, 2000 at 03:25 UTC
    by hawson
    I'm constantly having to clean out space on lots of computers, and looking at several screens of 'du' output hurts. So I wrote this little script to parse and format the output from 'du'. I know, I know, it's not strictly perl, but monks should be aware that there are thing that exist outside these cloistered walls. N.B. Since this is meant to be used in a pipe, it's usually all on a single line, and without comments.
    Simple Calculator
    on Jun 29, 2000 at 01:20 UTC
    by ncw
    A simple perl calculator for use on the command line. See code for instructions.
    ButtonFactory
    on Jun 28, 2000 at 16:40 UTC
    by t0mas
    A package that creates custom png buttons.
    UserId checker
    on Jun 10, 2000 at 04:58 UTC
    by brick
    This program is meant to munge through N passwd files and check for logins with multiple UIDs, UIDs with multiple logins, and logins with a UID of zero (0) that are not root.
    pcal
    on Oct 22, 2000 at 05:45 UTC
    by japhy
    pcal displays calendar information for the next X months (it defaults to just the current month). With just a little modification, it could be made to act exactly like the cal utility found on most Unix machines.
    denies
    on Jul 28, 2000 at 07:07 UTC
    by Anonymous Monk
    Creates and mails a report on ipchains DENY entries in the /var/log/messages* files. The script remembers the last entry from the last run so you only get new entries on the next run. Add it to your crontab to generate periodic reports.
    ppm.xml made more human-friendly
    on Aug 03, 2000 at 11:52 UTC
    by Intrepid

    Please use caution!

    I have found out from external sources that in XML, whitespace outside of tags can be significant, and that although the present version of PPM does not mind how my script changes <CITE>ppm.xml</CITE>, a future version may. It might be better, therefore, not to use this script.

    The Perl Package Manager (with ActivePerl) writes to a file named ppm.xml each time a module is installed using PPM. It doesn't add nice whitespace to the file, however, resulting in a mess if one ever needs to or wants to (out of curiosity) go in there and see what has happened before. This little (slightly "anal" :) utility script can be called from the very end of <CITE>PPM.bat</CITE> (another file that comes standard with the installation of ActivePerl) by adding the line:

    CALL fixPPMXMLfile

    to the file below the lines that match this:

    __END__ :endofperl

    at the end of the batchfile. This kicks off your cleaner which adds some whitespace to make more human-friendly a file which, it is to be admitted, is ordinarily only machine-read.

    Killer
    on Aug 04, 2000 at 18:56 UTC
    by ergowolf
    replace the word process with what you are looking for. I used this script to kill a particularly tough process at work. I am sure this is the hard way, but its how I did it and it works. I would like to see the easy way though.
    NIST Atomic Clock Time
    on May 11, 2000 at 02:50 UTC
    by reptile
    Uses LWP::UserAgent to get the current date and time (Eastern) from the NIST Atomic Clock website at www.time.gov This code is public domain.
    Cropping a postscript file
    on May 08, 2000 at 21:40 UTC
    by ZZamboni
    This script allows you to select a portion of a postscript file and crop it. The whole file is included in the result, but the appropriate commands are included to crop it to the section you select. Instructions for use are included in the script.
    Workaround Cern for Amanda status
    on Apr 15, 2000 at 23:34 UTC
    by providencia
    This was created because the webserver is ancient that runs
    the internal operations page and cannot run cgi as it's owner
    So I couldn't create this as cgi(that's what our previous web-
    master told me). So this program runs as root and still
    gives the same information.

    It's a specific solution to a specific problem, but you never know
    who may find it useful.
    c2printf
    on Mar 09, 2000 at 16:38 UTC
    by Anonymous Monk
    This script takes a C source code file as input and converts it to C source code that will printf exactly that file. I uses an array of translation rules so it should be expandable (and maybe they're not complete yet?). If you use this together with a little elisp snippet that puts the output of a programm into the current buffer it is quite useful.
    DHCP and DNS Compare
    on Mar 30, 2000 at 20:14 UTC
    by Hyler
    For Windows NT administrators. Compares DHCP server and DNS server info to see if they match reasonably. Requires NT Resource Kit installed.
    Tarball Cleaner
    on Feb 02, 2000 at 10:28 UTC
    by Elihu
    Call this with a tarball to remove the contents of the tarball. Very useful if the tarball dumps in the current directory.
    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-08-29 05:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (275 votes), past polls