方法一:在系统上创建systemctl服务,通过systemctl status | start | restart | disable | enable autoRun.service方式自启服务
1、在/etc/systemd/system下创建autoRun.service文件
2、编辑autoRun.service文件
/etc/systemd/system/autoRun.service
[root@bogon system]# cat auto_run_script.service
[Unit]
Description=Run a Custom Script at Startup
After=default.target
[Service]
ExecStart=/opt/project/autoRunScript.sh
[Install]
WantedBy=default.target
[root@bogon system]#
3、重新加载配置文件
systemctl daemon-reload
systemctl enable autoRun.service
方法二:使用crontab特殊计划任务
crontab -e
@reboot /opt/project/autoRun.sh
特殊计划任务写法补充
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".