duandun3178 2013-08-24 16:24
浏览 169

从cron脚本编写crontab会返回127错误

I'm working with some scripts which must be executed from crontab. Some of them rewrite crontab.

in.php defines if read.php should be run by crontab. Then read.php is executed by crontab. This works fine.

When read.php is executed, it might detect that it should be not running, if this happens, it rewrites crontab to avoid its own execution, until in.php rewrites crontab again. The problem is that this second step is not working.

I have been looking for the error and I have found that my cron.txt is correctly written. However, crontab command fails and returns 127 error. But when I execute read.php manually all works fine.

Both scripts use the same functions to rewrite crontab. But this is happening just in read.php, not in in.php.

Is there a time to rewrite crontab since it executes a task? It may explain my problem, because in.php takes longer time to be executed than read.php.

Thank you!

PD: I have checked that the path to cron.txt in crontab command is the same if it is executed automatically and if I execute it manually.

EDIT: When I speak about rewriting crontab I refer rewrite a cron.txt file and to execute crontab [path]/cron.txt

  • 写回答

1条回答 默认 最新

  • doumangzhen7204 2013-08-24 16:53
    关注

    Without access to your code, we can only speculate about what goes wrong, but a much simpler and more robust solution would be to add a wrapper which decides whether or not to execute the real job, and simply always run the wrapper from crontab. In the simplest possible case, execute a file only if it exists:

    55 * * * * test -x hourly && ./hourly
    

    Rename $HOME/hourly to something else to prevent it from executing.

    Or, if the conditions are simple, just make the script bail out early if the conditions are not met.

    case $moon_phase in full | new ) exit 0 ;; esac
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害