-rwxr-xr-x | bin/NS2SetMac.sh | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/bin/NS2SetMac.sh b/bin/NS2SetMac.sh index 51810ae..e6111c7 100755 --- a/bin/NS2SetMac.sh +++ b/bin/NS2SetMac.sh | |||
@@ -1,3 +1,7 @@ | |||
1 | # store/set MAC address for given interface | 1 | # this script is part of networksettings2 package |
2 | # purpose : set fixed MAC address for network devices that | ||
3 | # have random addresses (like usb) | ||
4 | # | ||
5 | |||
2 | NS2MacStore=/etc/NS2 | 6 | NS2MacStore=/etc/NS2 |
3 | 7 | ||
@@ -5,12 +9,16 @@ NS2MacStore=/etc/NS2 | |||
5 | 9 | ||
6 | if [ -z "$1" ] | 10 | if [ -z "$1" ] |
7 | then | 11 | then |
8 | exit 0 | 12 | exit 0 |
9 | fi | 13 | fi |
10 | 14 | ||
11 | if [ -f ${NS2MacStore}/$1.mac ] | 15 | if [ -f ${NS2MacStore}/$1.mac ] |
12 | then | 16 | then |
13 | # set this mac | 17 | # set this mac |
14 | /sbin/ifconfig $1 hw ether `cat ${NS2MacStore}/$1.mac` | 18 | X=`cat ${NS2MacStore}/$1.mac` |
19 | if [ ! -z "$X" ] | ||
20 | then | ||
21 | /sbin/ifconfig $1 hw ether $X | ||
22 | fi | ||
15 | else | 23 | else |
16 | # remember current mac for all times | 24 | # remember current mac for all times |
@@ -18,5 +26,9 @@ else | |||
18 | X=${X#*HWaddr } # strip till HWaddr | 26 | X=${X#*HWaddr } # strip till HWaddr |
19 | X=${X%% *} # remove trailing spaces | 27 | X=${X%% *} # remove trailing spaces |
20 | echo ${X} > ${NS2MacStore}/$1.mac | 28 | if [ ! -z "$X" ] |
29 | then | ||
30 | # valid mac address | ||
31 | echo ${X} > ${NS2MacStore}/$1.mac | ||
32 | fi | ||
21 | fi | 33 | fi |
22 | exit 0 | 34 | exit 0 |