如何通过PHP脚本调试Shell进程执行?

乔尔·马修(Joel G Mathew)

我有一个php脚本,应该在机器上执行一个perl脚本并打印进程ID。执行它时,我发现进程ID已打印出来,但是在检查进程列表时,我找不到perl脚本的正在运行的进程。

我将该命令记录到一个文件中,发现该命令是正确的,并且从shell执行该命令可以正确执行该脚本。这两个脚本均归www-data所有。

if (isset($_GET['path'])) {
   $spath=$_GET['path'];
   $cmd="/usr/bin/perl ".getcwd().'/rotten2torrent.pl "'.$spath.'"';
   $outputfile="tmpfile";
   $pidfile="pid";
   if (isset($_GET['recursion'])) {
      $recursion=1;
      $cmd=getcwd().'/htmlrscrape.pl '.$spath;
   } else {
      $recursion=0;
   }  
   $command =  $cmd . ' > /dev/null 2>&1 & echo $!; ';
    $pid = exec($command, $output, $return);
   fwrite($logfile, "\n". "Command: ".$cmd);
   print 'Download started with PID '.$pid;
   fwrite($logfile, "\n". "Download started with PID ".$pid);
   fwrite($logfile, "\n". "Output lines: ".$pid);
    fwrite($logfile, "\n". "Return code: ".$return);
   foreach ($output as &$value) {
    fwrite($logfile, "\n". $value); 
   }
} 

日志文件输出:

#cat dldebug.log
http://www.rottentomatoes.com/top/bestofrt/top_100_horror_movies/?category=10 test
Command: /usr/bin/perl /var/www/rotten2torrent.pl "http://www.rottentomatoes.com/top/bestofrt/top_100_horror_movies/?category=10"
Download started with PID 13147
Output lines: 13147
Return code: 0
13147
Done

我还查看了apache2访问和错误日​​志,但未显示错误:

tac /var/log/apache2/access.log | less

ip1 - - [16/May/2015:12:18:13 +0530] "HEAD / HTTP/1.1" 200 285 "-" "Cloud mapping experiment. Contact [email protected]"
ip2 - - [16/May/2015:11:54:41 +0530] "GET /dlnow.php?path=http%3A%2F%2Fwww.rottentomatoes.com%2Ftop%2Fbestofrt%2Ftop_100_horror_movies%2F%3Fcategory%3D10&action=test HTTP/1.1" 200 321 "http://199.204.187.162/dlbox.php" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36"

我该如何调试?我假设Shell进程开始执行,但随后被系统终止。如何监视正在显示的错误?

exec不是服务器上php.ini中的禁用功能。我已经在服务器上使用php exec测试了“ ls -l”,并且已执行。

我尝试使用htop监视进程执行,但是找不到启动的进程。

乔尔·马修(Joel G Mathew)

为了调试,我将exec命令更改为 $command = $cmd . ' > debug.log 2>&1';

现在,日志输出显示未找到启动脚本所需的perl模块。我错过了这一点,因为在我的shell中,我在测试时以root用户身份运行。www数据用户无权访问这些模块。

要解决此问题,我必须为www-data创建shell和sudo权限。然后,我以www-data身份登录,使用cpan minus来安装所需的模块,然后注销。现在,脚本开始正常运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从PHP脚本执行Shell

来自分类Dev

如何通过shell脚本执行vim命令

来自分类Dev

如何杀死通过cron运行的shell脚本中的进程?

来自分类Dev

如何在PHP中执行Shell脚本

来自分类Dev

如何区分通过Shell执行的PHP脚本中的服务器?

来自分类Dev

如何通过使用Shell从另一个PHP脚本执行一个PHP脚本?

来自分类Dev

如何通过 PHP 触发 Shell 脚本

来自分类Dev

通过crontab执行shell脚本

来自分类Dev

如何执行shell脚本?

来自分类Dev

如何执行shell脚本?

来自分类Dev

调试Shell脚本:不执行语法检查

来自分类Dev

如何通过Gimp从Shell执行Python-Fu脚本

来自分类Dev

如何通过外部python脚本在Django shell中执行代码?

来自分类Dev

如何通过Node.js执行mongoDB Shell脚本?

来自分类Dev

通过shell脚本执行“ mysqldump”时如何提供密码

来自分类Dev

如何通过Gimp从Shell执行Python-Fu脚本

来自分类Dev

尝试通过shell脚本杀死进程

来自分类Dev

在Linux中脚本执行结束后,php exec或shell_exec不会终止其进程

来自分类Dev

如何在一行中转换Shell脚本并从Python子进程执行它?

来自分类Dev

我如何列出在shell脚本(或类似的东西)运行期间执行的所有进程

来自分类Dev

如何使Shell脚本不创建子进程并且不等待子执行

来自分类Dev

PHP执行外部进程使脚本挂起

来自分类Dev

PHP执行外部进程使脚本挂起

来自分类Dev

通过php执行python脚本

来自分类Dev

通过网址执行php脚本

来自分类Dev

如何从Hubot执行Shell脚本

来自分类Dev

如何重新启动gnome shell,但通过脚本将其守护进程?

来自分类Dev

通过Maven执行后退出Shell脚本

来自分类Dev

如何从soapui groovy脚本执行shell脚本?

Related 相关文章

热门标签

归档