Identifying Orphan Files
As many of our readers know, we switched hosting companies
recently.
Something we noticed are many files we're uncertain whether or not are
still needed.
We do a lot of development, a lot of testing, and sometimes
we neglect to remove the test files. This has been going on
for 8 years.
The possibly orphan files were brought to our attention
when we moved our sites to the new hosting company. Are
the files adrift with no purpose or do we need them?
To answer that question, we put some JavaScript into each
of the orphan files. The JavaScript launches a CGI script
that logs it's use.
If an orphan doesn't show up on the log after a reasonable
amount of time, it can be removed from the server. With
many thousands of files on our server, removing these
reduces clutter.
I'll show you how to do it.
Note: This can be done only with files of text, ie web
pages and files that might be included in web pages. Image
files can't be tagged this way.
Here is the Perl script. Install it on your server with any
file name that makes sense to you. The example JavaScript
assumes "logger.cgi", but you may use any legal name.
The above Perl script prints the date and time according
to the server and then prints any information sent to it
by the JavaScript. The log file is tab-delimited so most
popular desktop spreadsheet programs can import it.
You'll notice the Perl script allows you to specify the log
file name. Also, the place where the date formating occurs
is marked in case you want to change it.
The JavaScript (see below) needs to be pasted into each
orphan file you want to monitor.
It has a place where you specify the URL of the above Perl
script. And it also has a place where you can identify the
individual orphan file the JavaScript is pasted into.
The JavaScript sends your identity information about the
orphan file to the logging script, along with the URL of
the web page where the file was used at.
This provides more than just a heads up for you. If the
file was included in a web page, you also know the URL of
the web page it was included in.
The identification of files that do not show up in the logs
after a reasonable period of time can be considered orphans.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©2006 Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.