0

我有一个要从 shell 脚本运行的命令:

vim-cmd vmsvc/getallvms

我想将此命令的输出转换为一个变量,即:

60 abc-trunk [xxxxx] abc-trunk/abc-trunk.vmx rhel6_64Guest vmx-10 xxxx OEM,CentOS 6.7,来自 xxxx.yyyyyy.com 的最新中继安装

我想将输出转换为变量并从变量中删除所有内容,所以我只剩下一个将读取“abc-trunk”的变量

4

1 回答 1

0

Your can do this using PHP,

$result= "60 abc-trunk [xxxxx] abc-trunk/abc-trunk.vmx rhel6_64Guest vmx-10 xxxx OEM, CentOS 6.7, latest trunk install from xxxx.yyyyyy.com";
$lines = explode("/n",$result);     
foreach($lines as $key=>$val)
            {
                $val = preg_replace('/\s+/', '|', $val);
                $l = explode("|", $val);
                if($l['1'] <> "")
                {
                    $vm=$l['1'];
                }
            }
print_r($vm);

This will Output "abc-trunk".

Edit the code inside foreach loop as per your need.

于 2016-12-08T11:42:45.960 回答