5.开机自动运行脚本--三种方法

方法一:

修改/etc/rc.d/rc.local文件

方法二:

用crontab -e

@reboot /home/script.sh

方法三:

仅适用于systemd系统,即ps aux,pid为1的进程是systemd的就是

 

 在/etc/systemd/system/下建一个文件

vim script.service

[Unit]
Description=Run a Custom Script at Startup
After=default.target

[Service]
ExecStart=/home/script.sh

[Install]
WantedBy=default.target

把脚本/home/script.sh放在/etc/systemd/system/下

更新systemd配置文件

systemctl daemon-reload
systemctl enable script.service

 

posted @ 2020-08-11 16:02  天涯160  阅读(807)  评论(0)    收藏  举报