注:
1)将不变的部分放入带反斜杠的一对括号 \( \) 中并在替换时用 \1 引用。
2)\S用于匹配除单个空格符之外的所有字符。
awk -F"=" '{if($1=="IP")print("IP=102.117.2.23")}' filename >filename.new 2>/dev/null
#vi config.shifconfig
echo "Please input:0/1/2"
read dir
case $dir in
0)
echo -n "Please enter new ip for eth0:"
read ip0
echo -n "Please enter netmask for eth0:"
read mask0
ifconfig eth0 $ip0 netmask $mask0
service network restart
1)
echo -n "Please enter new ip for eth1:"
read ip1
echo -n "Please enter netmask for eth1:"
read mask1
ifconfig eth1 $ip1 netmask $mask1
service network restart
2)
echo -n "Please enter new ip for eth2:"
read ip2
echo -n "Please enter netmask for eth2:"
read mask2
ifconfig eth2 $ip2 netmask $mask2
service network restart
*)
echo "you can only input 0,1,2"
esac
# chmod +x config.sh
# ./config.sh
Please input:0/1/2
0
Please enter new ip for eth0:10.254.197.10
Please enter netmask for eth0:255.255.252.0
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface:[ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
================================================
以上是我运行的结果,但我只有一个网卡,所以只是测了eth0. 还没有做错误处理,所以ip和netmask一定要输入对了才好用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)