重启时运行shell脚本

问题描述 投票:0回答:2

尝试了两种方法,似乎都没有用:

crontab -e

@reboot sleep 60;/home/linuxbox/script.sh

并在/etc/systemd/system/script.service中创建了服务:

[Unit]
Description=a generic service to run on reboot

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/bin/bash /home/linuxbox/script.sh
Type=simple
User=linuxbox
Group=linuxbox
WorkingDirectory=/home/linuxbox

我跟着systemctl daemon-reload

不确定目前出了什么问题,不胜感激。

linux cron systemd reboot
2个回答
0
投票

您启用了crond吗?

您可以启用并以它开头

sudo systemctl enable crond.service   

0
投票

ExecStart命令不应该

/bin/bash /home/linuxbox/script.sh

但应该是

/bin/bash -c "/home/linuxbox/script.sh"

© www.soinside.com 2019 - 2024. All rights reserved.