Ubuntu 18.04 開機後自動執行 rc.local

1.sudo su 切換到root權限

2.以root身分進入

1
lib/systemd/system/ 

查看是否有rc.local.service檔案, 一般都會有啦
若沒有檔案就走2-1

2-1

1
2
3
4
5
nano lib/systemd/system/rc.local.service
#文件最後加上
\[Install\]
WantedBy=multi-user.target
Alias=rc.local.service

然後存檔,離開

3.建立 rc.local 檔

1
2
3
cd /etc
sudo touch rc.local
nano rc.local

開啟rc.local的文件後,填入內容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#每次啟動自動執行Glances 命令列系統監控工具
glances -w
exit 0
```

4.rc.local 變更執行權限
```bash
sudo chmod +R 777 /etc/rc.local

5.啟用服務

1
sudo systemctl enable rc-local.service

6.重開機,如果有自動執行glances -w指令就是成功囉!

gist

參考

https://www.webteach.tw/?p=2621

Copyright © Bruce Huang All rights reserved.