TOOLBOX
Administrator and User Guide


1. INTRODUCTION

1.1 Overview

Toolbox is a set of tools for manipulating directories and files. It may be used to... The Find files function traverses a directory tree and finds all files above a specified size.
The Find text function traverses a directory tree, locates all [text] files that contain string X and (optionally) displays all lines containing string X.
The Check links function lists/checks all hyperlinks in files (web pages) - either a group of local files or specific local file.
The Show hex function shows the contents of a file in both hexadecimal and ASCII form.
The Edit function traverses a directory tree, locates all [text] files that contain string X and replaces all instances of string X by string Y.
The Obfuscate function edits a file to 'untidy' the source code, and so make it less re-usable.
The Rename function traverses a directory tree, locates all directory names and filenames containing upper-case characters and renames them (to lower case).
The Delete function traverses a directory tree and deletes all instances of filename X.
The Tidy Directories function 'tidies' a specific directory by deleting some or all of its contents.

1.2 Contents

    1. INTRODUCTION
       1.1 Overview
       1.2 Contents
       1.3 Document References
       1.4 Document Control
       1.5 Terms and Terminology
       1.6 Copyright
    2. TOOLBOX: INTRODUCTION AND OVERVIEW
    3. TOOLBOX: USER GUIDE
       3.1 Introduction
       3.2 Invocation and Arguments
       3.3 Action: Find files
       3.4 Action: Find text
       3.5 Action: Check links (hyperlinks) in files
       3.6 Action: Show file in hex form
       3.7 Action: Edit files
       3.8 Action: 'Obfuscate' files
       3.9 Action: Rename directories and files
       3.10 Action: Delete files
       3.11 Action: Tidy directories
    4. TOOLBOX: ADMINISTRATOR GUIDE
       4.1 Introduction
       4.2 Product Distribution & Contents
       4.3 Installing and Configuring Toolbox
       4.4 The Perl Script
       4.5 Restrictions and Deficiencies
       4.6 Test Status
       4.7 Errors and Diagnostics

1.3 Document References

  [1] Learning Perl (2nd Edition), Schwartz & Christiansen, O'Reilly & Associates, Inc.
  [2] Perl Cookbook, Christiansen & Torkington, O'Reilly & Associates, Inc.

1.4 Document Control

Document version: 1.0
Date: 15 September 1999
Script version (to which this document relates): 1.4
Document changes:

1.5 Terms and Terminology

CPAN Comprehensive Perl Archive Network
(A huge repository of Perl resources)
STDOUT standard output
UA user agent
URL uniform resource locator

1.6 Copyright

The following copyright applies to this document and associated script.
Copyright (c) 1999,2000 Beaumont Systems Ltd. All rights reserved.

The script may or may not be provided in source code form. This source code is the intellectual property of Beaumont Systems Ltd., and, as such, is subject to copyright and legal protection. It may not be copied or redistributed, in whole or in part, without the express permission of Beaumont Systems Ltd.


2. TOOLBOX: INTRODUCTION AND OVERVIEW


3. TOOLBOX: USER GUIDE

3.1 Introduction

3.1.1 Primary Functions

Toolbox is a set of tools for manipulating directories and files. The operations that it can perform are summarised in Section 1.1.

In essence, Toolbox is a set of tools that the author has developed for his own use, and across a range of operating systems. Toolbox simplifies and automates the tasks, and provides a portable solution.
It should be noted that some functions can be performed via other means, that is, by use of native tools. However, not all tasks can be performed via native tools, some tasks may involve the use of more than one tool (and the use of pipes), and some tasks may require use of non-intuitive arguments.

3.1.2 General Properties

3.2 Invocation and Arguments

3.2.1 Invocation

Toolbox may be made available in one of two release forms: Toolbox is invoked from the command line, and in one of several ways, depending on the platform (operating system) and the release form ...

Method of invocation Usage
tb [arguments] Platform: Any. Release form: Executable (object) only.
tb.pl [arguments] Platform: UNIX. Release form: Source only.
perl tb.pl [arguments] Platform: Microsoft Windows. Release form: Source only.

3.2.2 Arguments

Toolbox takes a number of arguments. The first of these specifies the basic action, and one of these must be selected. There is no default action. Subsequent arguments qualify this selection and are used as necessary.

The arguments are as follows...

Argument Used with Use Default
-f - Action: Find files. -
-g - Action: Find text. -
-l - Action: Check links (hyperlinks) in files. -
-s - Action: Show file in hex form. -
-e - Action: Edit files. -
-o - Action: 'Obfuscate' files. -
-r - Action: Rename directories and files. -
-d - Action: Delete files. -
-t - Action: Tidy directories. -
-lo xxx -l Specifies the extent of checking, where xxx is one of...
  • 0 - list links (without verification)
  • 1 - check some links (local files only)
  • 2 - check all links
Check all links
-lg -l Report good links (...as well as bad). Report bad links only
-lt ttt -l Set timeout value = ttt seconds. 20
-so xxx -s Set initial offset = xxx. 0 (start of file)
-sh -s Display current offset in hex. Decimal
-sw xxx -s Set width (block size per line) = xxx octets. 16
-sr -s Select raw mode (hex only, no offsets or ASCII values). Offset+hex+ASCII
-xd xxx -f,-g,-e,-r,-d,-t Specifies the (root) directory name. -
-xf xxx -g,-s,-o,-t Specifies the input filename. -
-xi -g,-d Ignore case. -
-xr all Restart log file. (Previous contents discarded). Append
-v all Set verbose mode = ON. Off
-h - Requests help. -
Table 2-1 : Program Arguments

Use Toolbox with no arguments (or -h) to obtain help information.

Upon invocation, Toolbox prompts the user for further parameters, depending on the action selected. See the following subsections for further information.

3.3 Action: Find files

3.3.1 General

When invoked with the -f argument, Toolbox finds files.
Specifically, it traverses a directory tree and finds all files at or above a specified size.

There are a number of other arguments that may be used in conjunction with -f. See Table 2-1 for a summary.

3.3.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Root (directory name) [.] ? :
  Size (bytes) ? :
Notes:

3.3.3 Outputs

Toolbox has the following outputs: The output takes the following form...
  File: file1.html, size: 8192
  File: file2.txt, size: 9600

3.4 Action: Find text

3.4.1 General

When invoked with the -g argument, Toolbox finds text.
Specifically, it traverses a directory tree, locates all (text) files that contain string X and (optionally) displays all lines containing string X.

There are a number of other arguments that may be used in conjunction with -g. See Table 2-1 for a summary.

3.4.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Root (directory name) [.] ? :
  String (to be found) ? :
Notes:

3.4.3 Outputs

Toolbox has the following outputs:

3.5 Action: Check links (hyperlinks) in files

3.5.1 General

When invoked with the -l argument, Toolbox checks links (hyperlinks) in files.

There are a number of other arguments that may be used in conjunction with -l. See Table 2-1 for a summary.
Use -lo to specify/restrict the extent of checking, ie to list links (without verification), check some links only (local files) or check all links.
Use -lg to report good links (as well as bad).
Use -lt ttt to alter the timeout value.
Use -xr to restart the log file.

3.5.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  URL/local directory/local filename ? :
Notes:

3.5.3 Outputs

Toolbox has the following outputs: The output takes the following form when listing links (using -lo 0) in a local file...
  --------------------
  TOOLBOX started. Wed Sep 15 23:38:56 1999.
  Filename: /usr/arf/web/html/andyf/aflinks.html, # links: 46
    Link: tagtype=a, name=href, value=http://cm.bell-labs.com/cm/cs/who/dmr/st.html.
    Link: tagtype=a, name=href, value=http://playground.sun.com/pub/ipng/html/INET-IPng-Paper.html.
    Link: tagtype=a, name=href, value=http://www.nexor.co.uk/public/rfc/index/rfc.html.
    Link: tagtype=a, name=href, value=http://www.cs.utah.edu/csinfo/texinfo/gnats/gnats.html.
    Link: tagtype=a, name=href, value=http://www.hwg.org/resources/html/index.html.
    Link: tagtype=a, name=href, value=http://WWW.Stars.com/Authoring/HTML/. (Full URL: http://www.stars.com/Authoring/HTML/).
    Link: tagtype=a, name=href, value=http://www.gamelan.com/.
    Link: tagtype=a, name=href, value=http://www.cgi-resources.com/.
    Link: tagtype=a, name=href, value=http://www.perl.com/.
    Link: tagtype=a, name=href, value=http://www.iconbazaar.com/.
    Link: tagtype=a, name=href, value=http://www.clipart.co.uk/.
    Link: tagtype=a, name=href, value=http://www.econ.cbs.dk/~gemal/urlheaven/index.html.
    Link: tagtype=a, name=href, value=http://www.data.com/.
    Link: tagtype=a, name=href, value=http://www.byte.com/.
The output takes the following form when checking links in a local file...
  --------------------
  TOOLBOX started. Thu Sep 16 11:11:57 1999.
  Filename: /usr/arf/web/html/beausys.html, # links: 9
    Link: tagtype=a, name=href, value=http://members.netscapeonline.co.uk/beaumontsystems/products/uwipnifss.html.
      ERROR: Problem accessing http://members.netscapeonline.co.uk/beaumontsystems/products/uwipnifss.html, response code=404, message=Not Found
    Link: tagtype=a, name=href, value=http://members.netscapeonline.co.uk/beaumontsystems/products/netdbov.html.
      ERROR: Problem accessing http://members.netscapeonline.co.uk/beaumontsystems/products/netdbov.html, response code=404, message=Not Found

3.5.4 Notes

It is important to note that this action can take a significant amount of time. It depends on the number of files to be checked, the total number of links to be checked and the amount of time required to check each link.
The checking of a link involves a finite amount of time. In particular, it involves sending a request to the web server and awaiting a response. Toolbox specifies a timeout period with the request to ensure that the request is terminated if a response is not received from the remote server within N seconds. At best, the server may respond immediately. At worst, the server may take some time to respond (because it is busy), or it may not respond at all (because it is extremely busy, currently 'down' or no longer exists).
Toolbox assumes a default timeout value of 20 seconds. The timeout value is important. If it is too short, then Toolbox may abandon a check before the remote server has had a chance to respond, and it may report an error when there isnt one. On the other hand, if the timeout value is too long, then Toolbox may waste time awaiting a response that will never come.

If you anticipate a large number of links, you may prefer to run Toolbox during a less busy period (perhaps overnight).

3.6 Action: Show file in hex form

3.6.1 General

When invoked with the -s argument, Toolbox shows a file in hex form.

There are a number of other arguments that may be used in conjunction with -s. See Table 2-1 for a summary.
Use -so xxx to select an initial offset. (Default=0, the start of the file).
Use -sh to display the current offset in hex. (Default=decimal).
Use -sw xxx to select the width (block size per line), in octets. (Default=16).
Use -sr to select 'raw' mode (show hex only, no offset and no ASCII).
Use -xf to specify the filename. If not, Toolbox will prompt you for it.
Use -xr to restart the log file.

3.6.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Filename ? :
  Filename (output) ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.6.3 Outputs

Toolbox has the following outputs: The output takes the following form (normal mode)...
  00000: 6d792024 61203d20 2731273b 0d0a0d0a    my $a = '1';....
  00016: 7072696e 74202224 615c6e22 3b0d0a24    print "$a\n";..$
  00032: 61202e3d 20273227 3b0d0a70 72696e74    a .= '2';..print
  00048: 20222461 5c6e223b 0d0a2461 202e3d20     "$a\n";..$a .= 
  00064: 2733273b 0d0a7072 696e7420 2224615c    '3';..print "$a\
  00080: 6e223b0d 0a246120 2e3d2027 2034273b    n";..$a .= ' 4';
  00096: 0d0a7072 696e7420 2224615c 6e223b0d    ..print "$a\n";.
  00112: 0a                                     .
Each line shows a block of octets from the file.
In normal mode (shown above), the output is presented as follows: In raw mode, the output consists of hex only (ie no offsets and no ASCII representations).

3.7 Action: Edit files

3.7.1 General

When invoked with the -e argument, Toolbox edits files.
Specifically, it traverses a directory tree, locates all (text) files that contain string X and edits them to replace (all instances of) string X by string Y.

There are a number of other arguments that may be used in conjunction with -e. See Table 2-1 for a summary.

This function is particularily useful for maintaining links in a collection of web pages (HTML documents).

3.6.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Root (directory name) [.] ? :
  String (to be found/replaced) ? :
  String (new) ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.7.3 Outputs

Toolbox has the following outputs:

3.8 Action: 'Obfuscate' files

3.8.1 General

When invoked with the -o argument, Toolbox 'obfuscates' files.
Specifically, it edits a file to obfuscate, or untidy, the source code, and so make it less re-usable.

There are a number of other arguments that may be used in conjunction with -o. See Table 2-1 for a summary.
Use -xf to specify the filename. If not, Toolbox will prompt you for it.

3.8.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Filename ? :
  Filename (output) ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.8.3 Outputs

Toolbox has the following outputs:

3.9 Action: Rename directories and files

3.9.1 General

When invoked with the -r argument, Toolbox renames directories and files.
Specifically, it traverses a directory tree, locates all directory names and filenames containing upper-case characters and renames them (to lower case).

There are a number of other arguments that may be used in conjunction with -r. See Table 2-1 for a summary.

3.9.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Root (directory name) [.] ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.9.3 Outputs

Toolbox has the following outputs: The output takes the following form...
  Directory /usr/AndyF: renaming as /usr/andyf
  File /usr/john/SUMMARY.TXT: renaming as /usr/john/summary.txt

3.10 Action: Delete files

3.10.1 General

When invoked with the -d argument, Toolbox deletes files.
Specifically, it traverses a directory tree and delete all instances of filename X.

There are a number of other arguments that may be used in conjunction with -d. See Table 2-1 for a summary.
Use -xf to specify the filename. If not, Toolbox will prompt you for it.

3.10.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Root (directory name) [.] ? :
  Filename ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.10.3 Outputs

3.11 Action: Tidy directories

3.11.1 General

When invoked with the -t argument, Toolbox 'tidies' a specific directory by deleting some or all of its contents.

There are a number of other arguments that may be used in conjunction with -t. See Table 2-1 for a summary.
Use -xd xxx to specify the name of the directory to be tidied.
Use -xf xxx to provide parameters in an input file (rather than interactively).

3.11.2 Inputs

On startup, Toolbox issues (some or all of) the following prompts:
  Directory name ? :
  Match expression ? :
Notes: Some arguments may be provided via the command line, in which case the relevant prompts are skipped.

3.11.3 Outputs

Toolbox has the following outputs: The output takes the following form...

--------------------
TOOLBOX started. Sat Dec 11 13:26:56 1999.
Action: 8. (Simulated)
Input file: test.dat.
Tidying directory: C:/Windows/Recent. Expression: *.htm.lnk
  Deleting object (file): C:/Windows/Recent/apolog.txt.lnk
  Deleting object (file): C:/Windows/Recent/index.html.lnk
  Deleting object (file): C:/Windows/Recent/tbov.html.lnk
  Deleting object (file): C:/Windows/Recent/tb.html.lnk
  Deleting object (file): C:/Windows/Recent/afcv4p.html.lnk
  Deleting object (file): C:/Windows/Recent/wtb.html.lnk
  Deleting object (file): C:/Windows/Recent/beausys.htm.lnk
  Deleting object (file): C:/Windows/Recent/wtbov.html.lnk
  Deleting object (file): C:/Windows/Recent/Test.dat.lnk
  Deleting object (file): C:/Windows/Recent/tb.log.lnk
Tidying directory: C:/Windows/Temporary Internet Files/Content.IE5. Expression: *
  Deleting object (file): C:/Windows/Temporary Internet Files/Content.IE5/index.dat
  Deleting object (file): C:/Windows/Temporary Internet Files/Content.IE5/desktop.ini
  Deleting object (directory): C:/Windows/Temporary Internet Files/Content.IE5/MRTZG5LA
  Deleting object (directory): C:/Windows/Temporary Internet Files/Content.IE5/X9371GUP
  Deleting object (directory): C:/Windows/Temporary Internet Files/Content.IE5/ID688HK0
  Deleting object (directory): C:/Windows/Temporary Internet Files/Content.IE5/4B8RAJMZ
  Deleting object (file): C:/Windows/Temporary Internet Files/Content.IE5/tb.log

3.11.4 Notes

This function requires a set of parameters, consisting of directory name and a match expression. The match expression provides a means of selecting a specific group of objects within the directory for deletion, eg *.* to delete all objects, *.tmp to delete all objects whose name ends with .tmp.
There are 3 ways to provide these parameters: The input file method has a number of advantages. First, it is more convenient if you have to tidy the same set of directories repeatedly. Second, it allows you to specify multiple sets of parameters, with one set per line. Third, it allows you to specify an optional second match expression for each directory.
The input file has the following characteristics: (Note the use of ';' as a field separator. The characters ':' and ' ' (space) are not used as a separator because these can legitimately occur in the directory name).


4. TOOLBOX: ADMINISTRATOR GUIDE

4.1 Introduction

This is the Toolbox Administrator Guide.

4.2 Product Distribution & Contents

4.2.1 Distribution Form

Toolbox is distributed in the form of a single archive file. (An archive file is one that contains a set of other files, and these other files must be extracted from the archive before they can be used).
It is available in one of two archive formats: (Note, however, that some Win32 zip utilities (such as WinZip) can handle .tar files, and there are some Unix utilities that can handle .zip files).

4.2.2 Distribution Contents

The distribution consists of...

4.2.3 File List

Filename Type Use Notes
tb.pl code - (Executable) Perl script
tb.html documentation Administrator and User Guide (this document) -
Table 3-1 : File List

4.3 Installing and Configuring Toolbox

4.3.1 Prerequisites

The prerequisites are... Perl. Perl packages are available for Unix, Win32 (Win95/98/NT) and other platforms. If the system on which you are intending to install Toolbox does not have a Perl package already installed, then you can obtain a Perl package in a number of ways... For more information on packages/libraries/modules, see document reference [2]. It includes a chapter on packages/libraries/modules, and a section on building and installing CPAN modules.

4.4 The Perl Script

4.4.1 Organisation

The Toolbox Perl script is organised as follows:

4.4.2 Perl Features

Toolbox employs the following Perl features and techniques: In addition, the script employs tips, techniques and optimizations obtained from the following sources:

4.5 Restrictions and Deficiencies

  1. Perl version: Toolbox was written using Perl 5 (Perl Release 5, 5.000 onwards).
    It has not been tested on earlier (ie pre- Release 5) Perl systems, and so may or may not work on such systems.

4.6 Test Status

Toolbox has been tested with and without the -w and -T flags.

Toolbox has been tested on the following platforms:

4.7 Errors and Diagnostics


Copyright (c) 1999,2000 Beaumont Systems Ltd. All Rights Reserved.