Crontab不执行bash脚本 [英] Crontab not executing bash script

查看:490
本文介绍了Crontab不执行bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少使用Linux,因此对bash脚本和cron作业没有任何经验。
实际上这是我的第一次尝试。因此,修复起来可能很简单。

I very very rarely use Linux and so don't have any experience with bash scripts and cron jobs. This is in fact my first attempt. So it's probably something really simple to fix.

我有以下内容:

/etc/cron.d /clear-mixtape-dir.sh
权限为:644

/etc/cron.d/clear-mixtape-dir.sh permissions are: 644

#!/bin/bash
# Clears the /tmp/mixtape2 directory
rm -rf "/tmp/mixtape2/"*

我的crontab文件看起来像这样:

My crontab file looks like so:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

*/15 * * * * /etc/cron.d/clear-mixtape-dir.sh >/dev/null 2>&1

我正在尝试执行每隔15分钟执行一次.sh脚本。

I'm trying to execute the .sh script every 15 minutes.

我发现的所有内容都表明该方法可以正常工作,但事实并非如此。

Everything i've found says this should work, but it doesn't.

在这种情况下,文件权限(对/ tmp / mixtape2 /中的文件的权限)是否重要?
或可能是在实际.sh脚本上设置的权限-也许它们需要设置为可执行文件?

Does anything like file permissions (on files within /tmp/mixtape2/) matter in this case? Or perhaps the permissions set on the actual .sh script - maybe they need setting to executable?

任何建议都值得赞赏。

推荐答案

/etc/cron.d 中的脚本中删除.sh扩展名,会被调用。

Remove the .sh extension from the script in /etc/cron.d and it will be called.

运行部件会忽略名称中带有句点的文件,因此.sh扩展阻止您的脚本运行。

run-parts ignores files with a period in the name, so the .sh extension is preventing your script from running.

来自 man cron -


文件必须符合run-parts(8)所使用的命名约定:它们必须仅由大小写字母,数字,下划线和连字符。

Files must conform to the same naming convention as used by run-parts(8): they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens.

这篇关于Crontab不执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆