-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_eth.sh
More file actions
executable file
·68 lines (56 loc) · 1.89 KB
/
change_eth.sh
File metadata and controls
executable file
·68 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# ScriptsName: change_eth.sh
# ScriptsPath:/root/scripts/change_eth.sh
# Purpose: change network config
# Edition: 1.0
# CreateDate:2016-05-17 14:31
# Author: Payne Zheng <zzuai520@live.com>
Help() {
echo "usege: You entered the network card device is incorrect, please re-enter"
echo "Try: chnet szwork|dghome|szhome"
exit 1
}
Restart() {
/etc/init.d/network restart &> /dev/null
}
Success() {
echo -e "$GREEN_COLOR Chnet Success ^_^ $RES"
}
CheckNowStatus() {
ping -c 1 baidu.com &>/dev/null
test $? -eq 0 && { echo -e "$RED_COLOR === network now is good, no need to change === $RES"; exit; }
}
test $# -ne 1 && Help
CheckNowStatus
grep -qP '^dgwork$|^dghome$|^szhome$' <<<"$1" || Help
location=$1
device_eth0=/etc/sysconfig/network-scripts/ifcfg-eth0
device_eth1=/etc/sysconfig/network-scripts/ifcfg-eth1
device_eth2=/etc/sysconfig/network-scripts/ifcfg-eth2
device_eth3=/etc/sysconfig/network-scripts/ifcfg-eth3
RED_COLOR='\E[1;33m'
GREEN_COLOR='\E[1;33m'
RES='\E[0m'
case $location in
"dgwork" )
sed -i '/ONBOOT/s/no/yes/' $device_eth0 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth2 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth3 &> /dev/null
;;
"dghome" )
sed -i '/ONBOOT/s/no/yes/' $device_eth2 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth0 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth3 &> /dev/null
;;
"szhome" )
sed -i '/ONBOOT/s/no/yes/' $device_eth3 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth0 &> /dev/null
sed -i '/ONBOOT/s/yes/no/' $device_eth2 &> /dev/null
;;
* )
Help
;;
esac
Restart
ping www.baidu.com -c 3 &> /dev/null
test $? -eq 0 && Success