Ubuntu 18.04 開機自動執行 指令 rc.local

1.sudo su 切換到root權限
2.以root身分, 進入lib/systemd/system/ 查看是否有rc.local.service檔案, 一般都會有啦XD
若沒有就走2-1
2-1.nano lib/systemd/system/rc.local.service
文件最後加上
[Install]
WantedBy=multi-user.target
Alias=rc.local.service

存檔
3.建立 rc.local 檔
cd /etc
sudo touch rc.local

nano rc.local
文件內容如下
#!/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 變更執行權限
sudo chmod +R 777 /etc/rc.local

5.啟用服務
sudo systemctl enable rc-local.service

6.重開機如果有自動glances -w就是成功囉!

參考

沒有留言: