Re: Run a script automatically when an IP is added

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 26Aug2014 09:37, Yong Huang <yong321@xxxxxxxxx> wrote:
Oracle's clusterware can migrate a VIP from one server to another. I'd like to have the target server automatically run a shell script once the new IP comes in. Is there a way to detect that and trigger execution of this script?

This
http://www.diglinux.com/2012/04/07/linux-heartbeat-ip-fail-over-2/
looks like what I need. But I wonder if a simpler solution exists, preferably without installing extra package. In fact, yum install heartbeat on my Red Hat box didn't find the package.

Since nobody has replied, this is something you can do yourself with a little script. As a starting point, this lists all the IPv4 addresses on my host (current OSX, but adjusting for Linux "ifconfig" output should be easy):

  ifconfig -a | sed -n 's/^ inet \([1-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\) .*/\1/p'

Note that the first whitespace before "inet" is a TAB character.

Have a look at "ifconfig -a" on your system and adjust the regexp.

(Or, if you care only about a specific interface, use "ifconfig eth0" or whatever to monitor just that interface.)

Then all you would do is run that, pipe it through "sort -u", and put the output in a file.

Next time, run it, sort, put in a temp file.

Compare them ("cmp -13 old-file tmp-file" should be useful) to get a list of new IP addresses. When you get a new one, do what you want. Save the tmp-file to the old-file for use on the next run.

Put it in cron to run regularly.

Cheers,
Cameron Simpson <cs@xxxxxxxxxx>

WFO: the normal throttle position for Denizens, squids, and unfortunates on
     50cc Honda step-throughs.

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list




[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux