运行定时任务
在过去的几个小时里,我一直对 cronjobs 感到困惑。我已阅读文档和示例。我了解基础知识和概念,但还没有任何工作。所以我希望能得到一些帮助来解决这个完全菜鸟的困境。
最终目标是安排每天执行 django 函数。在此之前,我想知道我可以安排任何旧脚本运行,首先运行一次,然后定期运行。
所以我想: 1)编写一个简单的脚本(可能是 bash 脚本),它可以让我确定它确实运行成功,或者失败。 2) 安排这个脚本在整点运行
我尝试编写一个 bash 脚本,简单地将一些文本输出到终端:
#!/bin/bash
echo "The script ran"
然后我将其放入 .txt 文件中,
MAILTO = *****.******@gmail.com
05 * * * * /home/vadmin/development/test.sh
但什么也没发生。我确信我做错了很多事情。我从哪里开始解决所有这些问题?
've been puzzling over cronjobs for the last few hours. I've read documentation and examples. I understand the basics and concepts, but haven't gotten anything to work. So I would appreciate some help with this total noob dilemma.
The ultimate goal is to schedule the execution of a django function every day. Before I get that far, I want to know that I can schedule any old script to run, first once, then on a regular basis.
So I want to:
1) Write a simple script (perhaps a bash script) that will allow me to determine that yes, it did indeed run successfully, or that it failed.
2) schedule this script to run at the top of the hour
I tried writing a bash script that simple output some text to the terminal:
#!/bin/bash
echo "The script ran"
Then I dropped this into a .txt file
MAILTO = *****.******@gmail.com
05 * * * * /home/vadmin/development/test.sh
But nothing happened. I'm sure I did many things wrong. Where do I start to fix all of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Crontab 本身不会发送电子邮件,定义
MAILTO
变量也不会改变它的想法。您需要执行以下操作:首先,确保
mail -s ADDRESS
实际上是从您的邮箱发送电子邮件。然后调用
crontab -e
编辑crontab文件。如下所示:保存文件并关闭编辑器,cron 应该会拾取更改。这应该有效,您应该会收到电子邮件。然后,您可以将
echo "Hello from Cron script"
替换为您的脚本。希望有帮助。祝你好运!
Crontab does not send emails by itself, and defining
MAILTO
variable doesn't change its mind. You need to do something like this:First, make sure that
mail -s ADDRESS
is actually of sending email from your box.Then invoke
crontab -e
to edit crontab file. Put something like this:Save the file and close editor, cron should pick up changes. This should work and you should get email. Then you can replace
echo "Hello from Cron script"
with your script.Hope it helps. Good luck!