The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help on most efficient search prvnrk Shell Programming and Scripting 16 04-08-2008 01:24 PM
Efficient way of Awk braindrain Shell Programming and Scripting 4 07-11-2006 11:01 AM
Look into this and suggest if any changes needed me_haroon AIX 1 07-03-2006 02:39 AM
Is there a more efficient way? SelectSplat Shell Programming and Scripting 6 12-16-2005 12:59 PM
Efficient I/O S.P.Prasad High Level Programming 1 12-09-2003 09:38 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2006
Junior Member
 

Join Date: Sep 2006
Posts: 16
Stumble this Post!
Can you suggest a more efficient way for this?

Hi

I have the following at the end of a service shutdown script used in part of an active-passive failover setup:
Code:
###
# Shutdown all primary Network Interfaces
# associated with failover
###

# get interface names based on IP's
# and shut them down to simulate loss of
# heartbeatd

PRIV_IP="10.0.4.81"
INT_IP="192.168.0.10"

PRIV_IF=`ifconfig |grep -B 1 ${PRIV_IP}| awk '{ printf ("%s\t" , $1) }'| awk '{ print $1 }'|tr -d ":"`
INT_IF=`ifconfig |grep -B 1 ${INT_IP}| awk '{ printf ("%s\t" , $1) }'| awk '{ print $1 }'|tr -d ":"`


ifconfig ${PRIV_IF} down
ifconfig ${INT_IF} down
exit 0
Essentially it uses the IP to obtain the name of the interface associated with that IP, and then shutdown the relevant interface (this simulates a loss of connection and instigates failover. I have another NIC that I am able to ssh into to make sure that the server remains in its failed state - i.e. the script does not shutdown the primary server). The PRIV_IP, for example, is associated with bond0. The output for bond0 is the following:

Code:
bond0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 10.0.4.81 netmask 0xff000000 broadcast 10.255.255.255
        inet x.x.x.x netmask xxxxxxxxxx broadcast x.x.x.x
        ether 00:0d:93:9d:9e:8f 
        media: autoselect (1000baseT <full-duplex,flow-control>) status: active
        supported media: autoselect
        bond interfaces: en0 en1
Is there any way to make this more elegant/efficient?

Mike
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-20-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
Code:
###
# Shutdown all primary Network Interfaces
# associated with failover
###

# get interface names based on IP's
# and shut them down to simulate loss of
# heartbeatd

PRIV_IP="10.0.4.81"
INT_IP="192.168.0.10"

PRIV_IF=`ifconfig |grep -B 1 ${PRIV_IP}| awk -v FS=: '{ print $1 }`
INT_IF=`ifconfig |grep -B 1 ${INT_IP}| awk -v FS=: '{ print $1 }'`


ifconfig ${PRIV_IF} down
ifconfig ${INT_IF} down
exit 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0