大网数据广告活动
服务器运维问答

What is the best directory to place your cron jobs?

· 52CE 我爱测

We have a machine that executes cron jobs. We'd like to upload (via scp) cron job files to. Here is an example of a cron job file (test.cron): * * * * * echo "test" > /tmp/test_cron This runs if you do it using crontab -e then sa…

问题原文

原帖链接 · Titi · CC BY-SA 4.0

We have a machine that executes cron jobs. We'd like to upload (via scp) cron job files to. Here is an example of a cron job file (test.cron):

* * * * * echo "test" > /tmp/test_cron

This runs if you do it using crontab -e then save, and then that ends up in /var/spool/cron/crontabs/$USER, we can't use this anymore (company policy).

If I place this file test.cron in the /etc/cron.d it doesn't run. Do I need to change this file syntax or put this file elsewhere so it's picked up by cron deamon and ran?

Update:

When I paste contents of the test.cron into crontab -e it gets executed. My crontab syntax seems to be valid.

My question is: Where do I need to put/drop/place test.cron file with the content above, so that it gets picked up by cron daemon?

More context: I don't know in advance at what interval the cron file command will need to be ran. None of these are probably a good place "cron.daily/ cron.hourly/ cron.monthly/ cron.weekly/" I could be wrong that's why I'm asking this question.

已采纳解答

原帖链接 · Christo · CC BY-SA 4.0

/etc/cron.d is a feature of the crond that may have to be explicitly enabled. It is enabled by default on Debian-based distros. So /etc/cron.d is the right place when you are on a Debian derivative.

The cron manpage on Debian says:

Files in [/etc/crond.d] 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. This means that they cannot contain any dots.

So you have to rename your test.cron to eg. test_cron and it should start to work.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-12-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。