在树莓派上,我正在尝试编写一个简单的脚本,它将允许我更改dhcpcd.conf文件中的静态ip设置。除了dns服务器之外,下面的脚本可以正常工作。对于该行,sed语句似乎不起作用,因为它包含由空格分隔的两个ip地址。脚本如下:
#!/bin/bash
currip=$(cat /etc/dhcpcd.conf | grep -e '^static ip_address=' | cut -d= -
f2)
currgw=$(cat /etc/dhcpcd.conf | grep -e '^static routers=' | cut -d= -f2)
currdns=$(cat /etc/dhcpcd.conf | grep -e '^static domain_name_servers=' |
cut -d= -f2)
echo "current IP is $currip"
echo "current GW is $currgw"
echo "current DNS servers are $currdns"
echo "Enter new static ip in form of x.x.x.x/x: "
read newip
echo "Enter new GW in form of x.x.x.x: "
read newgw
echo "Enter new DNS servers in form of x.x.x.x x.x.x.x: "
read newdns
echo "currip is $currip"
echo "new ip will be $newip"
echo "new dns will be $newdns"
sed -i -e "s@$currip\b@$newip@g" /etc/dhcpcd.conf
sed -i -e "s@$currgw\b@$newgw@g" /etc/dhcpcd.conf
sed -i -e "s@$currdns\b@$newdns@g" /etc/dhcpcd.conf
chip=$(cat /etc/dhcpcd.conf | grep -e '^static ip_address=' | cut -d= -
f2)
chgw=$(cat /etc/dhcpcd.conf | grep -e '^static routers=' | cut -d= -f2)
chdns=$(cat /etc/dhcpcd.conf | grep -e '^static domain_name_servers=' |
cut -d= -f2)
echo "The ip has been changed to $chip"
echo "The GW has been changed to $chgw"
echo "The DNS server have been changed to $chdns"dhcpcd.conf文件中的行如下所示:
静态ip地址=192.168.126.7/24
静态routers=192.168.126.1
静态domain_name_servers=192.168.126.1 66.243.243.101
我需要如何为domain_name_servers调整我的sed语句?
https://stackoverflow.com/questions/47660306
复制相似问题