Systemd Timer不执行shell脚本

问题描述:

我一直在试图放在一起,一个非常简单的shell脚本,如果它尚未运行,它将启动红移。Systemd Timer不执行shell脚本

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

我试过多次运行该脚本,我确定它的工作原理。

我正在运行Manjaro i3 btw。 我又试图创建在/ usr/lib中/ systemd /系统/服务和定时器:

/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 

是的,该脚本的名称被重新转移。

/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 

我在哪里被告知它正在运行并启用。问题是,只要定时器击中标记,什么都不执行。任何想法我做错了什么?

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

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

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

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