Linux cronjob不工作(执行脚本) [英] Linux cronjob doesn't work (execute script)

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

问题描述

我使用命令crontab -e创建了cronjob:

I created a cronjob with the command crontab -e:

*/1 * * * * /var/lib/tomcat/webapps/ROOT/WEB-INF/scripts/test.sh 

此文件 test.sh 应该每分钟执行一次。但它不工作。

This file test.sh should be executed every minute. But it doesn't work.

如果我手动运行脚本,它工作正常。所以我认为问题是cronjob不是脚本;)

If I run the script manually it works fine. So I think the problem is the cronjob not the script ;)

是否有任何权限或其他阻止cronjob?

Are there any permissions or something else which block the cronjob?

cronjob语法是否正确?

Is the cronjob syntax correct?

Thx

推荐答案

p>一开始,你不需要 / 1 ,如果你想每一分钟。只需将分钟字段设置为 * 即可。

For a start, you don't need the /1 if you want it done every minute. Just setting the minute field to * will do.

接下来, (#!行如果存在):

Next, you should place, as the first lines in your test script (though after the #! line if it's there):

env >/tmp/test.sh.dummy
set >>/tmp/test.sh.dummy

并查看该文件是否显示。

and see if that file shows up.

这将告诉你脚本是否正在运行。

That will tell you if the script is running or not.

如果不是正在运行,请检查以确保 cron 本身正在运行:

If it's not running, check to make sure cron itself is running:

pax> ps -ef | grep cron | grep -v grep
root      1048     1  0 08:45 ?        00:00:00 cron

(我的)。

如果运行,最可能的问题是 cron 运行您的作业的环境不在环境附近壳给你。检查输出到您的 /tmp/test.sh.dummy 文件和您执行 env时您的shell给出的内容之间的差异;设置

If it is running, the most likely problem is that the environment under which cron runs your jobs is nowhere near the environment your shell gives you. Examine the differences between what was output to your /tmp/test.sh.dummy file and what your shell gives your when you execute env ; set.

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

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