bash crontab 在 arch linux 下不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23146514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:14:53  来源:igfitidea点击:

crontab not working under arch linux

linuxbashfindcrontab

提问by user3547439

I tried to set up a schedule to remove the old file and folder after several days. I put the following code in a script file and tried to use crontab to run it every day. The find command worked fine. but the crontab seems not execute the script file.

我试图设置一个时间表,在几天后删除旧文件和文件夹。我将以下代码放在脚本文件中,并尝试使用 crontab 每天运行它。find 命令工作正常。但是 crontab 似乎没有执行脚本文件。

I also use crontab for other tasks, i.e. rsync, they all work fine. I am wondering what might be the possible reason that crontab won't work in this case. And what could I do alternatively for the job? Thanks!

我也将 crontab 用于其他任务,即 rsync,它们都可以正常工作。我想知道 crontab 在这种情况下不起作用的可能原因是什么。我还能为这份工作做些什么?谢谢!

#!/bin/bash -x

find /media -type d -ctime +18 | xargs rm -rf

my crontab entries are

我的 crontab 条目是

10 09 * * * /root/rsync-shell.sh &
20 09 * * * /root/chg3gp2avi.sh &
30 09 * * * /root/clean_files_10days.sh &

the first two are the ones I set up before and work fine. The third one is the current one that won't work.

前两个是我之前设置的并且工作正常。第三个是当前不起作用的。

采纳答案by Sami Kerola

Is crond running?

crond 正在运行吗?

$ systemctl status crond
* crond.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

If not try to start it before debugging any further. If you have not configured sudo then use root privileges by some other means, such as logging in as root or via su command.

如果没有尝试在进一步调试之前启动它。如果您尚未配置 sudo,则通过其他方式使用 root 权限,例如以 root 身份登录或通过 su 命令。

$ sudo systemctl start crond

回答by mistige

It's renamed into cronie, so:

它被重命名为cronie,所以:

systemctl enable cronie

systemctl 启用 cronie

systemctl start cronie

systemctl 启动 cronie

# double-check:
ps aux | grep crond

# 再次检查:
ps aux | grep crond