Changeset 149


Ignore:
Timestamp:
Jun 3, 2010, 2:18:15 PM (15 years ago)
Author:
rock
Message:

增加多個網路介面的判斷

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nutchez-0.2/src/test/client_install_func.sh

    r148 r149  
    256256echo -e "\n= recall_hostname_ip (debug) ="
    257257
    258 net_interfaces=$(ifconfig | grep eth | cut -d " " -f1)
    259 declare -i i=1
    260 echo -e "\nWhich network use for this machine: "
    261 
    262 for net in $net_interfaces
    263     do
    264         echo "($i) $net"
    265         i=i+1
    266     done
    267 
    268 read net_choice
    269 echo "choice is $net_choice"
    270 
    271 net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
    272 
    273 ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
    274 net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
    275 #net_address=$(ifconfig eth"${net_choice}" | grep "inet addr:" | sed 's/^.*inet addr://g' | sed 's/Bcast.*$//g')
    276 
     258net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
     259net_nu=$(echo $net_interfaces | wc -w)
     260
     261# 若只有一個 eth 時
     262if [ "$net_nu" == "1" ]; then
     263
     264ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
     265net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
    277266echo "net_address is $net_address"
     267
     268# 若有多個 eth 時
     269else
     270    declare -i i=1
     271    echo -e "\nSystem have multiple network device, which network use for this machine: "
     272       
     273    for net in $net_interfaces
     274        do 
     275            echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
     276            i=i+1
     277        done
     278       
     279        read -p "Plz choice(1/2/3...): " net_choice
     280    if [ -z $net_choice ]; then
     281        net_choice=1
     282    fi   
     283   
     284    echo "choice is $net_choice"
     285    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
     286    ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
     287    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
     288    echo "net_address is $net_address"
     289fi
     290
    278291echo "ssh nutchuser@$1 echo $net_address $(hostname) \>\> ~/nutch_nodes"
    279292su nutchuser -c "ssh nutchuser@$1 echo $net_address $(hostname) \>\> ~/nutch_nodes"
Note: See TracChangeset for help on using the changeset viewer.