Can you suggest a more efficient way for this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can you suggest a more efficient way for this?
# 1  
Old 11-20-2006
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
# 2  
Old 11-20-2006
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

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Suggest books

Hi, I'm a beginner and am learning c programming. I want to learn UNIX/LINUX in parallel. But I don't know difference between UNIX and LINUX and where they are applied in real life. As a beginner, some people asked me to start with UNIX. Please let me know some very good books for UNIX. Also a... (6 Replies)
Discussion started by: nerdbee
6 Replies

2. Shell Programming and Scripting

Any body suggest me.........!!!!

i am jaswanth, i am very new to unix/linux, upto now i worked in windows only., but i took coatching for unix.., and my sir teached all my classes in red hat linux and told me that all are same...!!! I know shall programming in red hat linux.., but now i installed opensloaris but the... (5 Replies)
Discussion started by: strgraphics
5 Replies

3. Shell Programming and Scripting

Please suggest how do i dump in .txt

I have requirement where i need to read data from .sh file. I am using awk to identify the particualr data and extracting it. mY CODE : awk '/SELECT/,/;/' SOURCE.sh I am getting output as SELECT.... .... FROM TABLE1; SELECT.... .... FROM TABLE2; SELECT.... .... FROM TABLE3; But my... (0 Replies)
Discussion started by: goutam_igate
0 Replies

4. Shell Programming and Scripting

please suggest me a site

hi i need to get the values from an xml file like the <TAG> values and write to a file please suggest me the commands and some good reading material sites so that i can implement (1 Reply)
Discussion started by: perlamohan
1 Replies

5. Shell Programming and Scripting

Can yum be used. If not please suggest.

Hi! I need to install a application from one server to several other servers. My script would copy the install-script to other machines and run it.Since it has to be non-interactive , just wondering if yum can be used for the same. Please let me know , if you guys are aware of other... (1 Reply)
Discussion started by: nua7
1 Replies

6. Shell Programming and Scripting

Please suggest some changes in my code

Hi All, I have made the following code which is taking 10-15 mins to execute completely. Here the file am using is very big( around 1050993843). Can any one make some changes in my code which reduces the time it takes to execute as am very much new to Unix(learner). One more thing, i have... (10 Replies)
Discussion started by: madhavsunduru
10 Replies

7. UNIX for Advanced & Expert Users

suggest book

Hi I am new to Unix/Linux I know commands and shell scripts which are useful for my project. But i need to know the basics and commands and shell scripts in detail and easy guide. Please refer a book. Thanks Haripatn (6 Replies)
Discussion started by: haripatn
6 Replies

8. AIX

Look into this and suggest if any changes needed

Hi, I am new script programming, I have written a script shown velow to read username and passwd from /etc/security/passwd, i am able to read username, but unable to grep lastupdate. please look into the code and suggest if any changes need. #!/bin/ksh USERNAME="" fname=/usr/bin/lastupdate... (1 Reply)
Discussion started by: me_haroon
1 Replies
Login or Register to Ask a Question