ubuntu18.04下如何开机自动执行自定义脚本?
答: 假设脚本路径为/usr/bin/myscript.sh,那么在/lib/systemd/system/下创建
一个myscript.service文件
1. /lib/systemd/system/myscript.service文件内容如下:
```
[Unit]
Description=myscript
[Service]
ExecStart=/usr/bin/myscript.sh
[Install]
WantedBy=multi-user.target
```
2. 给脚本可执行权限
```
$ sudo chmod 755 /usr/bin/myscript.sh
```
3. 使脚本自动启动
```
$ sudo systemctl enable myscript
```
4. 手动启动脚本
```
$ sudo systemctl start myscript
```