LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09: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, 08: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



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 02:06 PM
Using Squid/Iptables to redirect inbound web traffic to url/IP winairmvs Linux - Software 2 01-13-2010 11:41 AM
squid redirect url to different proxy aeby Linux - Software 0 08-13-2009 08:37 AM
redirect url munna_dude Linux - Software 2 02-15-2007 12:18 AM
url redirect Present Linux - Networking 4 01-26-2007 09:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:23 PM.

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
Open Source Consulting | Domain Registration