systemd 开机自动运行脚本

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

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中的内容就是业务相关ssh

而后经过systemd enable catchlog.service,来让其开机自动执行。ui

经过systemd startcatchlog.service 能够来验证是否能够调用到/home/catchlog.sh 这个脚本code