I'm modifying my squid redirection script to use a database...I'd prefer not to have to restart squid every time i update the redirections list. The non-database version (i.e. hardcoded perl S&R statements) works perfectly. The db version fails on some patterns.
here's a summary of what the script is supposed to do: given a URL, and a database of pattern & replacement key/value pairs check if any of the search patterns in the db can apply to it. if one can, then apply the pattern replacement and print the result, othewise print a blank line. The database is a .db file created with 'makemap hash redir <redir' from [:space:]-delimited source input like the following: ---cut here--- //.*excite.com/img/ads/.* //www.taz.net.au/blank_ad.gif //.*four11.com/g/ads/.* //www.taz.net.au/blank_ad.gif //.*zdnet.com/adverts/.* //www.taz.net.au/blank_ad.gif //.*yahoo.com/adv/.* //www.taz.net.au/blank_ad.gif //.*doubleclick.net/ad/.* //www.taz.net.au/blank_ad.gif //.*riddler.com/Commonwealth/bin/statdeploy.* //www.taz.net.au/blank_ad.gif ---cut here--- the main use i have for squid redirections here at home is to block out irritating flashing banner advertisements :-). i have different uses for it at other sites which is why i want this script to be fairly generic My script works fine with URLs containing all of the above patterns, EXCEPT for "//.*riddler.com/Commonwealth/bin/statdeploy.*". At first I suspected that i may have run into some size limitation in the db key but according to both the documentation and other test scripts i have written that is not the case. One of the test scripts just dumps the database in the same format as the search & replace statements in my working non-db version. except for sort order, the output is identical to what's in my script. In other words, it's almost certainly got nothing to do with perl's database functions...it's something wrong with my comparison: if (($url =~ /$key/)) Here's a test of the script. I've edited it slightly to put '***' in front of what I typed. $ squid.redir.db ***http://doubleclick.net/ad/12345.gif 203.16.167.2 - GET http://doubleclick.net/ad/12345.gif==>http://www.taz.net.au/blank_ad.gif ***http://www.netscape.com.au/inserts/images/advert.gif 203.16.167.2 - GET http://www.netscape.com.au/inserts/images/advert.gif==>http://www.taz.net.au/blank_ad.gif These two worked fine. ***http://riddler.com/Commonwealth/bin/statdeploy?12345.gif 203.16.167.2 - GET http://riddler.com/Commonwealth/bin/statdeploy?12345.gif==> For some reason, this one didn't, i got blank line output instead of the rewritten url. here's what my squid.redir script currently looks like (it's gone through several changes): ---cut here--- #!/usr/bin/perl $debug=1 ; use DB_File; use Fcntl; $|=1; $redir_file = 'redir.db' ; tie (%redir_db, 'DB_File', $redir_file, O_RDONLY, 0644, $DB_HASH) || die ("Cannot open $redir_file"); while (<>) { chop ; # Squid gives us: URL ip-address/fqdn ident method ($url, $address, $ident, $method) = /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ; $out="" ; $found = 0 ; while ((($key,$record) = each %redir_db) && ! $found) { if (($url =~ /$key/)) { $out = $url ; $out =~ s/$key/$record/ ; $found = 1 ; } ; } ; if ($debug) { print $url, "==>" ; } ; print $out, "\n" ; } untie %redir_db ---cut here--- I'm tempted to just give up and write it in C, but one of the purposes of doing this is to improve my perl. Any clues/suggestions/whatever would be appreciated. I need to get it working first, and optimise it for speed after that. thanks, craig -- craig sanders networking consultant Available for casual or contract temporary autonomous zone system administration tasks. -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .