php exec()未通过cron作业运行
几个小时以来,我一直在用头撞这个 我正在通过cron作业执行一个php脚本,除了php exec()未通过cron作业运行,php,bash,cron,raspberry-pi,gpio,Php,Bash,Cron,Raspberry Pi,Gpio,几个小时以来,我一直在用头撞这个 我正在通过cron作业执行一个php脚本,除了exec() <?php exec('gpio write 7 0'); // Open the file to get existing content $current = file_get_contents('log.txt'); // Append a new person to the file $current .= get_current_user().
exec()
<?php
exec('gpio write 7 0');
// Open the file to get existing content
$current = file_get_contents('log.txt');
// Append a new person to the file
$current .= get_current_user().' - '.date('H').":".date('i')." - gpio write 7 0\n";
// Write the contents back to the file
file_put_contents($log, $current);
?>
我尝试过给要执行的php文件赋予755
和777
权限,但没有成功
这就是我在执行sudo crontab-e
*/1 * * * * /usr/bin/php /var/www/check_time.php
任何帮助都将不胜感激
提前感谢。在线
exec('gpio write 7 0);
应该是吗
exec('gpio write 7 0');
??“似乎从未关闭过。您应该指定gpio
的路径,并给出确切位置,以便cron知道在哪里可以找到它,/usr/local/bin
不是由cron导入的:
/usr/local/bin/gpio
那么它将是:
exec('/usr/local/bin/gpio write 7 0);
不,那是我写这篇文章时的一个打字错误。不过这是个好主意。我已经相应地更新了帖子。感谢您在哪台计算机/服务器操作系统上运行它?似乎php没有执行脚本。在较新的ubuntu服务器上,您只需使用php
,而不用cron脚本中的/usr/bin/php
。他们中的一些人对编辑很挑剔——我看到你说你在ras pi上运行它,试试看
exec('/usr/local/bin/gpio write 7 0);