APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Unix Scripts > Tracking down a cgi bug
Printer Friendly Version





Tracking down a cgi bug

An awful lot of my web site is driven by cgi scripts. Sometimes I introduce bugs when I change something, but I usually notice that in my testing.

Recently I noticed some unusual errors in my web logs, and although I knew that they were related to a particular flat file that has information about pages, I couldn't figure out which script was triggering the errors.

What I was seeing was lines like this:


/usr/home/pcunix/www/data/control/Unixart: 40: Syntax error: word unexpected (expecting ")")
 

In the first place, that file shouldn't have been marked as executable, but of more interest to me was why any script was even trying to execute it. That meant that I must have been using a Perl "qx" command to call a shell script, which is something I rarely do, but unfortunately it is in enough scripts that I couldn't tell for sure where the problem was. The problem could be in any page, because each page is littered with SSI includes. It's not easy to track because a general script may call something more specific depending on what page it is, etc.

So, back to the logs. People do make enough other typing errors that I had a bracket of time stamps within which these errors had to be. Unfortunately, the smallest bracket was still several minutes, and that represents a lot of accesses. I cut out the 1800 lines where the problem had to be, and used vi to eliminate image accesses, leaving only pages and direct calls to scripts. I eliminated all unneeded text, leaving only the page or script, and then ran it through "sort -u" to get rid of duplicates. The file now looked something like

... 
/Unixart/winauth.html 
/Unixart/winrip.html 
/answers.html 
/cgi-bin/printer.pl?/Bofcusm/2305.html 
/currentpatch.html 
/index.html 
/newtosco.html 
/robots.txt 
/search.html 
...
 

I started a "tail -f" on the error log, and then ran this:

for i in `cat stufffromlogfile`
do
echo $i
lynx -dump http://aplawrence.com/$i > /dev/null
sleep 6
done
 

In a few minutes, I saw the errors pop into the error log, so I tried the last file name displayed by the script, and sure enough, that was it. Tracking to the faulty script was then easy. The script was doing something like

$cmd="/usr/bin/grep $this $thatfile";qx($cmd)
 

and under certain circumstances I needed to "chomp $this" and had not.

© August 2003 Tony Lawrence All rights reserved

If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?




More Articles by Tony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Auto FTP Manager

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




 I sell and support
 Kerio Mail server
pavatar.jpg

This post tagged:

       - Administration
       - Programming
       - Web/HTML




Unix/Linux Consultants

Skills Tests

Guest Post Here