使用 PHP 解析 BackupPC 的输出
我尝试解析“BackupPC_serverMesg status Hosts”的输出。
我得到的输出:
Got reply: %Status = (" admin " => {"endTime" => "1645958205","activeJob" => 0,"state" => "Status_idle"},"192.168.1.50" => {"lastGoodBackupTime" => "1645944158","deadCnt" => 0,"reason" => "Reason_nothing_to_do","activeJob" => 0,"state" => "Status_idle","aliveCnt" => 1560,"endTime" => "","needLink" => 0,"startTime" => "1645970401","type" => "incr","userReq" => undef}," trashClean " => {"endTime" => "1642317435","activeJob" => 1,"state" => "Status_link_running"}," admin1 " => {"endTime" => "1645956676","activeJob" => 0,"state" => "Status_idle"});
我不知道如何解析它。 我需要来自“192.168.1.50”的所有内容。
你知道如何解决吗?
谢谢你的帮助
马茨
i try to parse the output from "BackupPC_serverMesg status hosts".
The output i get:
Got reply: %Status = (" admin " => {"endTime" => "1645958205","activeJob" => 0,"state" => "Status_idle"},"192.168.1.50" => {"lastGoodBackupTime" => "1645944158","deadCnt" => 0,"reason" => "Reason_nothing_to_do","activeJob" => 0,"state" => "Status_idle","aliveCnt" => 1560,"endTime" => "","needLink" => 0,"startTime" => "1645970401","type" => "incr","userReq" => undef}," trashClean " => {"endTime" => "1642317435","activeJob" => 1,"state" => "Status_link_running"}," admin1 " => {"endTime" => "1645956676","activeJob" => 0,"state" => "Status_idle"});
I don´t have a Idea how i can parse it.
I need all from "192.168.1.50".
Do you have i idea how to solve it?
thank you for help
Matze
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文档 https://backuppc.github.io/backuppc/ BackupPC_serverMesg 命令您始终会获得输出在 Perl hash 的文本版本中,您需要在 Perl 中进行 eval() ,然后只有您可以在 PHP 中获得 JSON 格式。
以下是主机的 cmd 输出之一:-
我编写了一些代码来解析 PHP
输出中的此输出字符串:
此外,要在 Perl 中对日志的所有输出进行此解析,请检查此存储库代码 https://github.com/plepe/backuppc-print-status/blob/master/backuppc-status-json
As per docs https://backuppc.github.io/backuppc/ BackupPC_serverMesg Commands you always get output in text version of perl hash that you need to be eval() inside Perl, then only you can get JSON format in PHP.
Following is one of the cmds output from hosts:-
I wrote some code to parse this output string in PHP
Output:
Moreover to do this parse in Perl for all output from logs, check this repo code https://github.com/plepe/backuppc-print-status/blob/master/backuppc-status-json