执行脚本
1 2
| #!/bin/bash /bin/echo $(/bin/date +%F_%T) >> /tmp/start.log
|
方法一:修改/etc/rc.local
编辑 rc.local
/bin/bash /scripts/start.sh > /dev/null 2 > /dev/null
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
| ```
```bash #查看最后一行 tail -n 1 /etc/rc.local ```
#### 重启系统查看日志 ```bash cat /tmp/start.log ```
### ### 方法二:<font style="color:rgb(61, 68, 80);">chkconfig管理</font>
可参考文章 [Linux配置开机自启动执行脚本的两种方法](https://www.linuxprobe.com/linux-open-sh.html)
### 检验IP脚本 ```bash #!/bin/bash
#需要校验的IP IP_ADDR=172.18.1.110
#获取本机IP地址列表 machine_ips=$(ip addr | grep 'inet' | grep -v 'inet6\|127.0.0.1' | grep -v grep | awk -F '/' '{print $1}' | awk '{print $2}')
#输入的IP与本机IP进行校验 ip_check=false for machine_ip in ${machine_ips}; do if [[ "X${machine_ip}" == "X${IP_ADDR}" ]]; then ip_check=true fi done
if [[ $ip_check == true ]] then echo "true" exit 1 else echo "false" exit 1 fi ```
**tips:**
+ [shell](https://www.runoob.com/linux/linux-shell-process-control.html) + [nohup](https://www.runoob.com/linux/linux-comm-nohup.html) + [stat](https://www.runoob.com/linux/linux-comm-stat.html)
|