shell脚本快速入门之-----linux设置 自定义脚本开机启动,一键式部署网卡配置文件

一、 赋予可执行权限

chmod +x /etc/rc.d/rc.local

二、 编辑启动文件

vim /etc/rc.d/rc.local

三、 在 /etc/rc.d/rc.local 中 加入 自己的执行脚本 & 后台运行

sh /opt/ping.sh &

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

#touch /var/lock/subsys/local
sh /opt/ping.sh &

四、脚本如下

#!/bin/bash
ip=www.baidu.com
ping -c 2 -w 3 -i 0.3 $ip &>/dev/null
if  [ $? -eq 0 ]
 then
echo " 可以ping的通百度"
 else
 echo "正在更改你的网卡"
sed -i '/^IPADDR=/cIPADDR=192.168.110.132' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i '/^GATEWAY=/cGATEWAY=192.168.110.2' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i '/^DNS1=/cDNS1=8.8.8.8' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "网卡配置文件已改完  正在重启网络服务"
systemctl restart network
fi

ping -c 2 $ip &>/dev/null
if [ $? -eq 0 ] ;then
 echo "一切准备就绪"
 else
  echo "请检查你绑定的网卡是不是vm8"
  fi
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值