LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 06-10-2010, 10:43 PM   #1
marx_long
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Rep: Reputation: 0
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
 
Old 06-13-2010, 09:59 PM   #2
marx_long
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Anybody can help me? i thinks there are something wrong with my perl script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid how to redirect url gubak Linux - Networking 3 03-04-2010 03:06 PM
Using Squid/Iptables to redirect inbound web traffic to url/IP winairmvs Linux - Software 2 01-13-2010 12:41 PM
squid redirect url to different proxy aeby Linux - Software 0 08-13-2009 09:37 AM
redirect url munna_dude Linux - Software 2 02-15-2007 01:18 AM
url redirect Present Linux - Networking 4 01-26-2007 10:08 AM


All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration