systemd 开机自动运行脚本

1:首先在/etc/systemd/system/catchlog.service 中建立后缀为server的文件。如本例

root@d:/home# cat catchlog.service
[Uint]

Description=catch log

[Service]
ExecStart=/bin/sh /home/catchlog.sh

[Install]
WantedBy=multi-user.target
Requires=ssh.service
After=ssh.service
root@:/home#

例如这个就是在ssh 服务ready后执行/home/catchlog这个shell,这个shell中的内容就是业务相关

然后通过systemd enable catchlog.service,来让其开机自动执行。

通过systemd startcatchlog.service 可以来验证是否可以调用到/home/catchlog.sh 这个脚本

猜你喜欢

转载自blog.csdn.net/tiantao2012/article/details/81121152