![Cronjob 不运行。类似的 cronjob 确实运行。Env Vars 有问题??? 涉及 Fedora。涉及 psql](https://linux22.com/image/678481/Cronjob%20%E4%B8%8D%E8%BF%90%E8%A1%8C%E3%80%82%E7%B1%BB%E4%BC%BC%E7%9A%84%20cronjob%20%E7%A1%AE%E5%AE%9E%E8%BF%90%E8%A1%8C%E3%80%82Env%20Vars%20%E6%9C%89%E9%97%AE%E9%A2%98%3F%3F%3F%20%E6%B6%89%E5%8F%8A%20Fedora%E3%80%82%E6%B6%89%E5%8F%8A%20psql%20.png)
我有像这样的 cronjobs
* * * * * /usr/bin/psql -U usename dbname -c "select usename, now(), pg_terminate_backend(pid) from pg_stat_activity where state like 'idle%' and (now() - query_start) > interval '2 hour';" &> /home/fedora/terminate_backend.log
* * * * * /usr/bin/psql -U usename dbname -c "vacuum analyze;" &> /home/fedora/vacuum.log
第二个正在运行并生成请求的(尽管无用)日志。上面的没有创建日志,我有理由相信它没有运行。
我尝试/usr/bin/echo "DUMB" > /home/fedora/dumb.log;
在前面添加但仍然什么也没有出现。
看起来是这样
* * * * * /usr/bin/echo "DUMB" > /home/fedora/dumb.log; /usr/bin/psql -U usename dbname -c "select usename, now(), pg_terminate_backend(pid) from pg_stat_activity where state like 'idle%' and (now() - query_start) > interval '2 hour';" &> /home/fedora/terminate_backend.log
任何帮助都非常感谢。这可能与环境变量有关吗?如果查看env
并尝试添加主机 127.0.0.1,则没有任何结果。顺便说一句,真空吸尘器可以工作,所以...
答案1
答案是在为什么我的 crontab 不工作?我该如何排除故障?,但直截了当地说,它是%
。来自man 5 crontab
:
The entire command portion of the line, up to a newline or a "%"
character, will be executed by /bin/sh or by the shell specified in the
SHELL variable of the cronfile. A "%" character in the command, unless
escaped with a backslash (\), will be changed into newline characters,
and all data after the first % will be sent to the command as standard
input.
包含 的 crontab 条目%
被截断(其余部分成为标准输入),因此命令失败和重定向已丢失。