Ruby, php shell_exec和crontab不能正常工作


Ruby, php shell_exec and crontab not working correctly

   <?php

    $scan = shell_exec('ruby /home/user/wpscan/wpscan.rb --url site.com --enumerate vp --follow-redirection --threads 1000');
    And than...
     ... extracting data from array(); (explode("plugins:", 1))
     ... writing data[1] to txt file ...
     ... send mysql query with rule if() {} else {} ...
     ... unlink(); *.txt file ...
    ...that's all
     ?>

你好。通过crontab运行ruby脚本(wpscan)有问题。将其添加为根目录:

crontab -e
在cron:

* * * * php5 /home/user/wpscan/wpscan.php

时间到了- php脚本启动,但是!工作的所有部分的脚本,除了$scan(部分与ruby脚本不工作)。

我试图显示脚本的完整路径到ruby bin: "which ruby",然后我复制这些路径到php文件。

Ruby安装在根目录下,所有脚本都有最大权限,并且在根目录下创建。在脚本中,我到处使用我需要连接的文件的完整路径。我也尝试使用php5的完整路径,但如果信任syslog.log -这并不重要。谁来帮帮我吧

好的。我已经解决了这个问题。据我所知,即使我们从cron运行ruby脚本,这并不意味着我们有足够的权利。所以,首先我为sudoers添加了一个修复-为root提供NOPASSWD。下一步:我检查脚本中的所有路径,因为它们必须是满的(即:/bin/php5 /home/test/test.php)然后在脚本中添加SUDO命令:

<?php
$test = shell_exec('sudo ruby /home/test/test.rb');
?>

别忘了chmod +x file.php

在cron中我使用了:

crontab -e
*   *   *   *   *   php5 /home/test/test.php

这就是全部:)现在一切都很好。我的一些错误:

  • 不要忘记从文件中做测试输出(即:sh run.sh> test.txt);

  • 使用邮件提醒器与cron,它可能也有帮助

  • 如果您从cron运行某些内容-最好使用完整路径

    感谢mudasobwa的建议和时间:)