【问题标题】:Systemd Timer not executing shell scriptSystemd Timer 不执行 shell 脚本
【发布时间】:2016-12-14 12:12:02
【问题描述】:

我一直在尝试编写一个非常简单的 shell 脚本来启动 redshift,如果它还没有运行的话。

#!/bin/sh
if ps -ef | grep -v grep | grep redshift-gtk; then
    exit 0
else
    /usr/bin/redshift-gtk &
    exit 0
fi

我已尝试多次运行该脚本,我确信它可以工作。

顺便说一句,我正在运行 Manjaro i3。 然后我尝试在 /usr/lib/systemd/system/ 中创建服务和计时器:

/usr/lib/systemd/system/redshift.service

[Unit]
Description=Runs redshift

[Service]
Type=simple
ExecStart=/bin/bash /home/velo/reshift.sh

[Install]
WantedBy=multi-user.target

是的,脚本的名称是 reshift。

/usr/lib/systemd/system/redshift.timer

[Unit]
Description=Runs redshift at given intervals
Requires=redshift.service

[Timer]
OnCalendar=*-*-* *:45:00
Persistent=true
Unit=redshift.service

[Install]
WantedBy=multi-user.target

计时器已更改为附近的任何相关分钟标记以触发它。每次更改 OnCalender 后,我都完成了:

>systemctl daemon-restart
>systemctl restart redshift.timer
>systemctl status redshift.timer

我被告知它正在运行并启用。问题是,只要计时器到达标记,什么都不会执行。知道我做错了什么吗?

【问题讨论】:

  • 你终于找到解决方案了吗?

标签: shell timer systemd manjaro


【解决方案1】:

使用systemctl list-timers --all 检查计时器的状态。

使用systemctl start redshift.timer 启动您的计时器。

此外,您应该将自定义脚本放在/etc/systemd/system 下。 /usr/lib 位置用于由软件包安装的脚本。

另请参阅:Run script every 30 minutes with systemd

【讨论】:

    猜你喜欢
    • 2020-07-20
    • 1970-01-01
    • 2016-02-21
    • 2018-03-31
    • 2020-10-19
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 2013-06-13
    相关资源
    最近更新 更多