linux shell sh 脚本开机自启动

文章目录

  • 1. 写脚本
  • 2. 给权限
  • 3. 设自启

1. 写脚本

写一个shell脚本
随便举个例子,每次开机在/home下touch个aa.txt

# 创建脚本
touch my_shell.sh

# 编写内容:
#!/bin/bash
touch /home/aa.txt

2. 给权限

给编写的脚本执行权限

sudo chmod +x  my_shell.sh

3. 设自启

# 修改/etc/rc.local文件
sudo vim /etc/rc.local

# 添加刚编写代码的路径
/ ... /my_shell.sh

# 可选项:如果没有/etc/rc.local
sudo touch /etc/rc.local
sudo chmod +x /etc/rc.local
# 接着重复上述操作

你可能感兴趣的:(linux,服务器,运维)