PHP脚本帮助输出yum数据,就像在shell中一样


PHP Script help output yum data just like it would in shell

嘿,我有一个问题,这里是问题的打印屏幕http://prntscr.com/3zy9kc

我想要它输出所有的数据从yum更新不只是一行这显示了更新的完整日志就像在shell中执行一样像这样

    Loading "installonlyn" plugin
    Loading "security" plugin
    Setting up repositories
    Reading repository metadata in from local files
    Installed Packages
    perl.i386                                4:5.8.8-10.el5_0.2     installed
    perl-Archive-Tar.noarch                  1.30-1.fc6             installed
    perl-BSD-Resource.i386                   1.28-1.fc6.1           installed
    perl-Compress-Zlib.i386                  1.42-1.fc6             installed
    perl-DBD-MySQL.i386                      3.0007-1.fc6           installed
    perl-DBI.i386                            1.52-1.fc6             installed
    perl-Digest-HMAC.noarch                  1.01-15                installed
    perl-Digest-SHA1.i386                    2.11-1.2.1             installed
    perl-HTML-Parser.i386                    3.55-1.fc6             installed

您只是在执行yum update。如果您需要保存命令的日志,请将其输出重定向到一个文件。

<?php 
shell_exec("yum update > update.log"); 
?>

然后读取文件。

PS:与其发布代码的截图,不如发布实际的代码。

我也遇到过同样的问题通过在浏览器中运行脚本,它以web服务器用户的权限执行,而命令需要root权限

以普通用户执行命令行脚本,除了"Loaded plugins: faststmirror"还会出现必须具有root权限的警告。

以root身份运行命令(例如在cronjob中),该命令返回要更新的文件的完整列表。