PERL Data File Search Script
This script was developed in support of the Powershell - Get
Inventory Script process which produces an HTML data file of most of the inventory data
from the workstation on which it is run. If these HTML files are copied to a server directory, it is
convenient to be able to search them for meaningful information, rather than just trolling through
them manually. Also there is no need to set up a
database to store the data in and the interaction overhead this causes. Because we are seaching ALL the
files content we are able to effectively isolate discrete data quickly. For example: If I am asked for
the number of installations of EndNote we have. I can set up a Keyword search for EndNote the returning
data will advise me of the number of workstations with Endnote (124 as of writing) and then list for me
the names of the workstations followed by the version details of EndNote on each workstation.
I used PERL for this purpose as the process runs for us at work, on a Linux intranet server, which of
course has PERL natively installed. "ActivePERL" for Windows can be loaded to most MS Windows machines.
In fact I wrote and tested the scripts on my Windows XP machine using ActivePERL and Apache Server.
Prerequisites
The instructions on this page assume that you have some understanding of how to load and configure
PERL and Web Server. If you have this knowledge then the following is in fact straightforward!
Script
The web page and the PERL script needed to implement this process are located in a zip file.
Download the file inventorysearch.zip and extract the
files "inventorysearch.html" and "01displayinv.pl". Copy "inventorysearch.html" to your web server
active page directory and copy "01displayinv.pl" to your CGI directory.
The PERL script "01displayinv.pl" is designed to locate all the HTML files in a single directory (specified
within the PERL script). These files are in fact named for the hostname of the workstations that originally
generated them, so the script either searches for computer names and displays the complete data sets for each computer
on one page, or it searches each file to locate the data string requested and display the results. Which type of
search is in fact done, is dependant on the users choice in the original search (Hostname or Keyword). If a
Keyword search is selected any html tags in the source code are removed, before comparing the remaining text data
with the string being sort. This reduces the number of false hits!
Confirm the following
The form in the "inventorysearch.html" search page calls the PERL script "01displayinv.pl" which is expected
to be found in the CGI directory. That directory is assumed to be the directory "/cgi-bin" of the Apache
Server. If you have a different location for CGI scripts, you will need to adjust the call in the source code
of "inventorysearch.html" on line 11.
The PERL script "01displayinv.pl" as supplied was written for an ActivePERL installation on my Windows XP machine.
On line 1 the shebang assumes the PERL executable is located at "C:/Perl/bin/perl.exe". If you have a different
location for PERL you will need to change the first line accordingly. On line 14 the $invfiles variable is set to
a directory on C Drive called "C:\inventory". In the script this line reads as:
$invfiles = "c:/invent~1"; If you are using a different directory location
for your inventory HTML files, then you will need to edit this line accordingly.
Searching other file types
I would note that this PERL script could in fact be quickly adapted to search a single directory of any other text
based file type, by adjusting the code on line 41, which currently strips off the HTML extension on the file
name...
|