dongsha7215 2014-07-24 06:53
浏览 49
已采纳

Ruby,php shell_exec和crontab无法正常工作

   <?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

     ?>

Hello. Have problems with running ruby script (wpscan) via crontab. Adding it as root:

crontab -e

In cron:

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

When time comes - php script launching, but! Works all parts of script except $scan (part with ruby script doesn't work).

I tried to show script full path to ruby bin: "which ruby" and than I copied those path to php file.

Ruby installed under root, all scripts have maximum rights and where created under root. In scripts everywhere I'm using full paths to files I need to connect. I also tried to use full path for php5, but if trust syslog.log - it doesn't matter. Help me somebody please :)

  • 写回答

1条回答 默认 最新

  • du9826 2014-07-26 17:07
    关注

    Ok. I have solved the problem. From what I understood, even if we run ruby script from cron, that doesn't mean that we have enough rights. So, first I made: added one fix to sudoers - providing root with NOPASSWD. Next: I check out all pathes in script as they must be full (i.e.: /bin/php5 /home/test/test.php) Than I add SUDO command in my script:

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

    Don't forget also chmod +x file.php

    In cron I used:

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

    And that's all :) Now all works fine. Some of my mistakes:

    • don't forget to do test output from the file (i.e.: sh run.sh > test.txt);

    • Use mail alerter with cron, it may help as well

    • If you running something from cron - better use full path

      Thanks mudasobwa for advices and time :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵