Difference between revisions of "Ops535 get device name"
(Created page with 'Sample script for locating the Network Device name that is connected to the Lab's network in TEL Buildinig. <pre> #! /bin/bash # get all the NIC device name in the system dev_nam…') |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
#! /bin/bash | #! /bin/bash | ||
# get all the NIC device name in the system | # get all the NIC device name in the system | ||
− | dev_names=$(/sbin/ifconfig | grep HWaddr| awk '{print $1}') | + | dev_names=$(/sbin/ifconfig | grep HWaddr| awk -F: '{print $1}' | sort -u ) |
+ | |||
+ | # for centos7 replace HWaddr with flags | ||
+ | |||
# set a loop to loop through each device name | # set a loop to loop through each device name | ||
# | # | ||
my_dev= | my_dev= | ||
− | TARGET_IP= | + | TARGET_IP=10.40 |
for d_name in ${dev_names} | for d_name in ${dev_names} | ||
Line 25: | Line 28: | ||
echo "The target NIC device name should be $my_dev" | echo "The target NIC device name should be $my_dev" | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category: OPS535]] |
Latest revision as of 11:44, 11 September 2017
Sample script for locating the Network Device name that is connected to the Lab's network in TEL Buildinig.
#! /bin/bash # get all the NIC device name in the system dev_names=$(/sbin/ifconfig | grep HWaddr| awk -F: '{print $1}' | sort -u ) # for centos7 replace HWaddr with flags # set a loop to loop through each device name # my_dev= TARGET_IP=10.40 for d_name in ${dev_names} do echo "Checking device name $d_name ..." status=$(/sbin/ifconfig $d_name|grep ${TARGET_IP}) if [ ! -z "$status" ] then echo "$d_name contains the target IP $TARGET_IP" my_dev=$d_name fi done echo "The target NIC device name should be $my_dev"