Hi All,
I'm working on trying to get a redirector script to add to a squid install and I am trying to debug the sample script but I am having a perl brain deficiency...
The script is called Redirector.pl and is as follows:
Code:
#!/usr/bin/perl
#
#
#
$|=1;
while (<>) {
@X = split;
$url = $X[0];
if ($url =~ /^http:\/\/.*/) {
$url =~ s/^http/https/;
print "302:$url\n";
} else {
print "403:$url\n";
}
}
So right off I see that
$| is taking stdin and using it as the value to operate on right? So when
@X=split; runs it is using whatever came in on stdin...
So to test this supposition (suppository? LOL) in the shell; it would be like:
Code:
echo http://some.url.info | ./Redirector.pl
I try this but I get:
Code:
./Redirector.pl: line 1: http://some.url.info: No such file or directory
How should I format the shell command to process properly? I need to maintain the pipe input as this is how squid will pass the data into the script... Also am I correct in assuming that the prints will just go out on stdout?
Your comments appreciated!
: EDIT :
I just added the "-w" to the "#!/usr/bin/perl" line and now I am getting the output to the screen when I run:
Code:
echo http://some.url.info | ./Redirector.pl
I now get:
Code:
302:http://some.url.info
Now I just have to figure out if that will break the way it works in squid...