简体   繁体   English

Crontab不会记录到文件

[英]Crontab doesn't log to file

I'm using crontab to execute my script every minute. 我正在使用crontab每分钟执行一次脚本。 But script don't work properly. 但是脚本不能正常工作。 This script should create file, log to another file and write to DB. 该脚本应创建文件,登录到另一个文件并写入数据库。 Only write to DB work. 仅写入数据库工作。 When I start script manually it work fine. 当我手动启动脚本时,它可以正常工作。 This is script: 这是脚本:

#!/usr/bin/php
<?php
require 'include/functions.php';
require 'include/logger.php';

$lock_file_name = "test.txt";
$lock_file = fopen($lock_file_name, "w+");
fclose($lock_file);

$log_file = "test.log";
$log = new log($log_file);
$logEnabled = 1;

if ($logEnabled==1) {$log->add("DEBUG: Start test.");}

if_dbconn();
$SQL = "INSERT INTO .`test` VALUES (1666, 6, 6, '6', '6', '6', '6', 6, '6', '6', 6, 6, 6, '6')";
mysql_db_query($db,$SQL);
?>

My cron look like this: 我的cron看起来像这样:

* * * * * /usr/bin/php -f /path/to/script/testCron.php > /dev/null

I would remove 我会删除

> /dev/null

and replace this with logging your stdout/stderr to a file to see what's going on. 并将其替换为将stdout / stderr记录到文件中以查看发生了什么。

> /tmp/cron.log 2>&1

Processes run under cron with a very limited environment, and I suspect your program is expecting something in the environment that isn't there, or is running in a directory that doesn't permit writing the log file. 进程在具有有限环境的cron下运行,并且我怀疑您的程序在该环境中期望的东西不存在,或者在不允许写入日志文件的目录中运行。 The above redirection will tell you immediately what's going on. 上面的重定向将立即告诉您发生了什么。

You need to specify a full path or change current directory before running script. 在运行脚本之前,您需要指定完整路径或更改当前目录。 The script has no access rights to create a log file in the directory where cron starts it. 该脚本无权在cron启动脚本的目录中创建日志文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM