shell 常用脚本维护笔记
Centos7.5 IP地址维护
#!/usr/bin/bash IPADDR=$(ifconfig|grep inet|sed '2,$d'|awk '{print $2}') GATEWAY=$(ifconfig|grep inet|sed '2,$d'|awk '{print $2}'|awk -F "." '{print $1"."$2"."$3".1"}') NETMASK=$(ifconfig|grep inet|sed '2,$d'|awk '{print $4}') DNS1=$GATEWAY DNS2=8.8.8.8 sed 's/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-eth0 > /etc/sysconfig/network-scripts/ifcfg-eth0.bk if [ $? -eq 0 ]; then cat >> /etc/sysconfig/network-scripts/ifcfg-eth0.bk << EOF IPADDR=$IPADDR GATEWAY=$GATEWAY NETMASK=$NETMASK DNS1=$DNS1 DNS2=$DNS2 EOF else echo "sed err" fi