LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cannot Redirect URL to another URL when the link is down with Squid (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-redirect-url-to-another-url-when-the-link-is-down-with-squid-813475/)

marx_long 06-10-2010 09:43 PM

Cannot Redirect URL to another URL when the link is down with Squid
 
Hi guys,

i have installed squid 2.6 on my centos. i have writen a shell script to ping a network and write to a file. write '1' if network up and '0' if network down. After that,a perl script will read the file and do the redirection.Perl will redirect to a fix URL example:www.google.com if the network down and do nothing when it up. i have put my perl script in squid.conf at url_rewrite_program /my_file_path.

below is my shell script for pinging:
Quote:

#!/bin/bash

while [ 1 ]
do
HOST=143.148.137.134

if ping -c 1 -W 1 $HOST >& /dev/null ; then
echo "$HOST is alive and kicking3" >> /etc/squid/dns_proxy
echo 1 > /etc/squid/status.txt
# service named restart
else
echo "$HOST is missing3" >> /etc/squid/dns_proxy
echo 0 > /etc/squid/status.txt
# service named restart
fi
sleep 10
done
below is my perl.script:
Quote:

#!/usr/bin/perl
$|=1;

while (<>)
{

open (MYFILE, 'status.txt');
$input = <MYFILE>;
close(MYFILE);

print "$input\n";

if ($input == 0)
{
@X = split;
$url = $X[0];
if ($url !~ /^http:\/\/www\.google\.com/)
{
$_ = $url;
s/^http:\/\/(.*)\/(.*)/http:\/\/www.google.com\/\2/;
print "301:$_\n";
}
}
else
{
print "$url\n"
}
}
My problem is client browser are not redirect to www.google.com even the network is down. It should go to the fix URL when the user click any URL in network down situation.it just appear cannot resolve host.
anyone can help me. maybe there's something wrong with my perl script.

thanks

marx_long 06-13-2010 08:59 PM

Anybody can help me? i thinks there are something wrong with my perl script.


All times are GMT -5. The time now is 10:22 AM.