LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2008, 04:27 AM   #1
please
Member
 
Registered: Apr 2007
Posts: 195

Rep: Reputation: 30
who is can edit this script?


Dear Sirs
I want to replace ping command to tcping or nslookup for link test in following script.who is can?Please help me.Our ISP was denied for ping

Best Regds
Please

#!/bin/bash
# Time between checks in seconds
SLEEPTIME=10

#IP Address or domain name to ping. The script relies on the domain being
#pingable and always available
TESTIP=203.81.71.69

#Ping timeout in seconds
TIMEOUT=2

# External interfaces
EXTIF1=eth1
EXTIF2=eth2

#IP address of external interfaces. This is not the gateway address.
IP1=10.243.49.4
IP2=10.160.65.233

#Gateway IP addresses. This is the first (hop) gateway, could be your router IP
#address if it has been configured as the gateway
GW1=10.243.49.1
GW2=10.160.64.1

# Relative weights of routes. Keep this to a low integer value. I am using 4
# for TATA connection because it is 4 times faster
W1=1
W2=1

# Broadband providers name; use your own names here.
NAME1=ADSL1
NAME2=ADSL2

#No of repeats of success or failure before changing status of connection
SUCCESSREPEATCOUNT=4
FAILUREREPEATCOUNT=1

# Do not change anything below this line

# Last link status indicates the macro status of the link we determined. This is down initially to force routing change

upfront. Don't change these values.
LLS1=1
LLS2=1

# Last ping status. Don't change these values.
LPS1=1
LPS2=1

# Current ping status. Don't change these values.
CPS1=1
CPS2=1

# Change link status indicates that the link needs to be changed. Don't change these values.
CLS1=1
CLS2=1

# Count of repeated up status or down status. Don't change these values.
COUNT1=0
COUNT2=0

while : ; do
ping -W $TIMEOUT -I $IP1 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?

if [ $RETVAL -ne 0 ]; then
echo $NAME1 Down
CPS1=1
else
CPS1=0
fi

if [ $LPS1 -ne $CPS1 ]; then
echo Ping status changed for $NAME1 from $LPS1 to $CPS1
COUNT1=1
else
if [ $LPS1 -ne $LLS1 ]; then
COUNT1=`expr $COUNT1 + 1`
fi
fi

if [[ $COUNT1 -ge $SUCCESSREPEATCOUNT || ($LLS1 -eq 0 && $COUNT1 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME1 from $LLS1
CLS1=0
COUNT1=0
if [ $LLS1 -eq 1 ]; then
LLS1=0
else
LLS1=1
fi
else
CLS1=1
fi

LPS1=$CPS1

ping -W $TIMEOUT -I $IP2 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?

if [ $RETVAL -ne 0 ]; then
echo $NAME2 Down
CPS2=1
else
CPS2=0
fi

if [ $LPS2 -ne $CPS2 ]; then
echo Ping status changed for $NAME2 from $LPS2 to $CPS2
COUNT2=1
else
if [ $LPS2 -ne $LLS2 ]; then
COUNT2=`expr $COUNT2 + 1`
fi
fi

if [[ $COUNT2 -ge $SUCCESSREPEATCOUNT || ($LLS2 -eq 0 && $COUNT2 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME2 from $LLS2
CLS2=0
COUNT2=0
if [ $LLS2 -eq 1 ]; then
LLS2=0
else
LLS2=1
fi
else
CLS2=1
fi

LPS2=$CPS2

if [[ $CLS1 -eq 0 || $CLS2 -eq 0 ]]; then
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then
echo Switching to $NAME2
ip route replace default scope global via $GW2 dev $EXTIF2
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then
echo Switching to $NAME1
ip route replace default scope global via $GW1 dev $EXTIF1
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then
echo Restoring default load balancing
ip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev

$EXTIF2 weight $W2
fi
fi
sleep $SLEEPTIME
done
 
Old 12-14-2008, 01:29 AM   #2
arunmathew1984
Member
 
Registered: Nov 2008
Posts: 31

Rep: Reputation: 15
What is it that you want to do again ???

Linux Archive

Last edited by arunmathew1984; 12-20-2008 at 11:23 AM.
 
Old 12-14-2008, 11:32 PM   #3
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
I don`t know how to replace ping to tcping
can U?
 
Old 12-17-2008, 07:47 AM   #4
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Smile

Quote:
Originally Posted by please View Post
I don`t know how to replace ping to tcping
can U?

If you just want to replace ping by tcping you can use

Code:
sed -i 's/ping/tcping/' file
Regards,
VIKAS
 
Old 12-17-2008, 09:32 AM   #5
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
Hi

Thanks for your reply
I will be came back if not OK.

Please
 
Old 12-21-2008, 02:34 AM   #6
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
hi

anybody can`t help me?

Thanks
 
Old 12-21-2008, 02:42 AM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
did you try vikas027's suggestion?
Quote:
sed -i 's/ping/tcping/' file
If yes, what went wrong?
errors....
 
Old 12-21-2008, 02:46 AM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
Please help me.Our ISP was denied for ping
You could search another ip to ping.
I also would increase the sleeptime, to prevent abuse
 
Old 12-21-2008, 08:01 AM   #9
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
Hi
Thanks for your advice

My ISP is stupid ISP.I can`t ping any IP they was denied for Dos virus attack.tcping can replace with your command but tcping can`t support with
ping option.Do you see in this configuration?I thought you all can help me so I posted.Do you have other way ?
I appreciate your help

Thanks
Please
 
Old 12-21-2008, 08:16 AM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Hi,

If you ping the IP every 10 seconds, it will block you.
The ISP is not stupid.
 
Old 12-21-2008, 09:43 PM   #11
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
Hi repo

10 seconds is we wrote for load balancing
Our ISP not allowed just 1 second.
see?
 
Old 12-22-2008, 02:57 AM   #12
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
ping 10.240.3.1
PING 10.240.3.1 (10.240.3.1) 56(84) bytes of data.
From 10.240.3.1 icmp_seq=1 Packet filtered
From 10.240.3.1 icmp_seq=2 Packet filtered
From 10.240.3.1 icmp_seq=3 Packet filtered
From 10.240.3.1 icmp_seq=5 Packet filtered
From 10.240.3.1 icmp_seq=6 Packet filtered
From 10.240.3.1 icmp_seq=7 Packet filtered
From 10.240.3.1 icmp_seq=8 Packet filtered
From 10.240.3.1 icmp_seq=9 Packet filtered
From 10.240.3.1 icmp_seq=10 Packet filtered
From 10.240.3.1 icmp_seq=12 Packet filtered
From 10.240.3.1 icmp_seq=13 Packet filtered
^C
--- 10.240.3.1 ping statistics ---
17 packets transmitted, 0 received, +11 errors, 100% packet loss, time 16132ms
 
  


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
script to edit all vhost at once. (cp a file into all of them) permalac Linux - Newbie 0 11-11-2008 04:33 AM
Edit sudoers by script snowman81 Programming 5 05-27-2008 06:52 PM
how to edit Mozilla startup script? sufianmunir Linux - Newbie 2 06-21-2004 06:51 PM
script edit file.. johnyy Linux - Software 4 01-22-2004 05:50 PM
edit login script athenerx Linux - Newbie 1 07-21-2002 11:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:02 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
Open Source Consulting | Domain Registration