TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Cron best practices

97 点作者 leejo大约 9 年前

6 条评论

euske大约 9 年前
The crontab command has one of the worst UI problems:<p>1. &quot;crontab -e&quot; lets you edit your crontab file, and &quot;crontab -r&quot; deletes it (without asking). The two keys are next to each other.<p>2. &quot;crontab&quot; (no arg) reads the contents of the crontab file from stdin and replaces it. When you accidentally hit Ctrl-D after it, your crontab is replaced with an empty file.
评论 #11654508 未加载
评论 #11655074 未加载
quentindemetz大约 9 年前
Cronic (<a href="http:&#x2F;&#x2F;habilis.net&#x2F;cronic&#x2F;" rel="nofollow">http:&#x2F;&#x2F;habilis.net&#x2F;cronic&#x2F;</a>) has been a real life-saver when it comes to using cron in production services. I&#x27;ve been using it for 4+ years without looking back.
评论 #11655403 未加载
评论 #11655324 未加载
makecheck大约 9 年前
I never edit a crontab directly. I use external files and reinstall them with &quot;crontab filename&quot; as needed. Then of course the files can be revision-controlled.<p>Also, I name the files according to host so I remember exactly where they were installed in a networked environment (e.g. &quot;host1.crontab&quot;, &quot;host2.crontab&quot;).
评论 #11654745 未加载
Ao7bei3s大约 9 年前
0. Use systemd timers instead.<p>OnCalendar= has a less insane format than cron, exit code and output logging, locking, proper command line tools, and other niceties like Persistent= (catch up e.g. after system was powered off) etc.<p>(And yes, you can still have user &quot;cronjobs&quot; if you enable systemd user session lingering.)
评论 #11655463 未加载
评论 #11654615 未加载
fideloper大约 9 年前
A few notes that I think are worth going over:<p>1. mysqldump can require quite a few more permissions than mentioned, depending on your utilization of mysql<p>2. The best way I&#x27;ve found to test the cron-like environmentis by following this: <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2135478&#x2F;how-to-simulate-the-environment-cron-executes-a-script-with" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2135478&#x2F;how-to-simulate-t...</a><p>Otherwise you run the risk of .profile (and similar) being loaded, where they will not be when run in the cron task.<p>3. Extra emphasis on using a lock file to avoid overlapping cron tasks!<p>4. I love using `time` or similar means to pass execution time somewhere (a log file, or a web hook), which helps with point 3.
kchoudhu大约 9 年前
Cron best practices: use anything else.