ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Got a problem.
OS is Linux Mandrake 9.2 with special routing soft running on it. That
soft handles several channels: two for source hosts and others for subscriber-hosts. All hosts have ip-adresses, and the term "channel" is of logical nature. Those channels could be opened and closed from the command line with the appropriate commands (like " # chclose 123", where 123 - channel number). One of the source hosts is the main source host, the other source host - is reserved source host. Both source hosts are online (their ip-addresses could be pinged) but only the channel for the main source host is up (opened).
The idea is to write a script that will at some periods of time (every 5 sec. for example) ping the main source host and when it will go down (destination host unreachable) the script will execute a command for closing its channel and another command for opening channel for reserved source host . The script must continue pinging the main source host and , when it will be up again, the script should execute a command for closing channel of the reserved source host and a command for opening channel for main source host.
<edit>
The idea with the ping is to just send out one packet. With some versions of ping you can do that with an option like: ping -c1 IP-Address
But with cygwin's ping you have to tell it the packet size then the number of packets. That is why it looks strange: ping IP-Address 56 1
This script I run on server (10.2.1.30)
The idea is that when $MAIN goes down, $ME will get 3 icmp packets, and when it'll
get up $ME will get 6 icmp packets.
I looked through packets with analyzer run on $ME in promisc mode, and only icmp
requests from server (10.2.1.30) to $MAIN are seen...
What it can be ?
I think the problem is because I used cygwin to write the first script. The ping command is completely different and has a totally different output than regular Linux ping. Sometimes I get stuck on a windows computer and cygwin is the only option I have.
Try your ping command in an xterm and check the output when the server is up and when the server is down. I rewrote your test script using regular Linux ping so hopefully this will work better.
#!/bin/bash
MAIN=10.2.1.15
ME=10.2.1.18
while true
do
until [ "`ping -c1 $MAIN |grep received|cut -d' ' -f8`" = "100%" ]; do
sleep 5
done
ping -c3 $ME
The cygwin ping had a decimal place in the percentage where a regular linux ping doesn't have one. Also the loss percentage is in a different place if the ping is good or bad but in cygwin it is always in the same place.
Due to the fact, that script is run on freeBSD, i had to change "cut -d' ' -f8" to
"cut -d ' ' -f7" 'cause the ping output on BSD is bit different from that in Linux.
Great. It's really seems simple now, though i had some ideas of writing it in C,
using ping code and symbol sockets..
Thank you, again!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.