Ubuntu 10.04 LTS Cron 作业不工作
我正在尝试使用 cronjob 来运行带有以下 Cronjobs 的 ruby 脚本(使用 Rails3 运行程序):
#!/bin/bash
0-59 * * * * echo 'script test'
# Begin Whenever generated tasks for: test1
* * * * * /bin/bash -l -c '/home/administrator/test1/script/rails runner /home/administrator/test1/app/create_flag.rb >> /home/administrator/test1/test.log 2>&1'
# End Whenever generated tasks for: test1
test1 是 Rails3 项目文件夹的名称。
添加了“echo 'script test'”作为测试,但似乎都没有执行。我目前使用的是 Ubuntu 10.04 LTS。
我是否写错了 cronjob?
I'm trying to use a cronjob to run a ruby script (Using Rails3 runner) with the following Cronjobs:
#!/bin/bash
0-59 * * * * echo 'script test'
# Begin Whenever generated tasks for: test1
* * * * * /bin/bash -l -c '/home/administrator/test1/script/rails runner /home/administrator/test1/app/create_flag.rb >> /home/administrator/test1/test.log 2>&1'
# End Whenever generated tasks for: test1
test1 is the name of the Rails3 project folder.
the "echo 'script test'" was added as a test, but neither seems to be executing. I'm currently using Ubuntu 10.04 LTS.
Have I written the cronjob incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
crontab 文件不是 shell 脚本。因此,您不需要在文件开头添加
#!/bin/bash
。另外,那里的空间也很可疑。尝试如下操作:另外,请确保以管理员身份调用 crontab -e 来编辑 crontab 文件。
Crontab file is not a shell script. So you don't need
#!/bin/bash
at the beginning of the file. Plus, spaces there are suspicious. Try something like this:Plus, make sure you call
crontab -e
asadministrator
to edit the crontab file.您需要指定运行命令的用户(您可以在此处查看格式 另外,echo 会输出“脚本测试”到什么地方?如果你想测试一下文件,这样你就可以实际看到 cron 作业的操作。
You need to specify the user which runs the commands (you can see the format here. Also the echo will output 'script test' to what? If you want a test try doing a touch on a file, so you can physically see the action of the cron job.
Cron 不使用您的用户环境,因此它不会具有与您相同的路径集。这意味着您应该使用命令的绝对路径。
Cron does not use your user environment, so it will not have the same path set that you have. This means that you should use absolute paths for commands.