Weblogs for w1d3

Posted by w1d3 on Fri 16 Feb 2007 at 17:54
Tags: ,
Yesterday I made this very simple cgi script to search in my music and video archive. It uses the 'locate' command and displays results in html so I don't have to log into my storage machine all the time :) It should remove all non-alphanumeric characters from query and also log the query words.
#!/usr/bin/perl -w

use CGI qw(:standard);
use strict;

print header;
print start_html(-title=>'web locate');

print startform,
"locate \ " ,
textfield(-name=>'query',
          -size=>20,
          -maxlength=>20),
" \ | grep mp3 wav avi mpg m2v wmv \ ",
submit(-value=>'Enter'),
endform;

print hr;
if(param){
        my $word = param('query');
        `echo \'$word\' >> search.log`;
        if(length($word) < 3){
                print "longer pls", p;
        }else{
                $word =~ tr/a-zA-Z0-9//cd;
                my $result = `locate -i $word | grep -i -e mp3 -e wav -e avi -e mpg -e m2v -e wmv`;
                $result =~ s/\n/
/g; print $result; } }; print end_html;
I hope that someone will find it useful, it's also quite easy to change it according to your needs, to find other file types etc.. feedback welcome! :)

 

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search