【发布时间】:2020-05-28 07:32:56
【问题描述】:
我创建了一个脚本,它将更改的文件从开发站点复制到运行良好的实时站点。
我现在正在尝试记录哪些文件已更改,然后将该列表添加到跟踪更改的数据库表中。
我使用shell_exec 为副本运行rsync,然后尝试修剪输出并添加\n 进行格式化。
输出类似于“发送增量文件列表 portalMaint.php 发送 27,659 字节接收 81 字节 55,480.00 字节/秒总大小为 101,582,367 加速为 3,661.95”。
这是我的代码:
$command = "sudo -S rsync -av ".$exclude." ".$source." ".$dest." --delete 2>&1";
// --- Issue command and check for errors.
$exErrors = shell_exec($command);
if (stripos($exErrors, "error:") !== false || stripos($exErrors, "[sudo]")) {
$error = "Uh-OH, we have a problem! Don't Panic!";
$errors = $exErrors;
include("head.php");
include("template_".$currentPage.".html");
include("foot.php");
exit();
}else{
$filesCopied = $exErrors;
$filesCopied = substr($filesCopied, 0, strrpos($filesCopied, " sent "));
$filesCopied = preg_replace("/\s+/", "\n", $filesCopied);
}
这不起作用。 $filesCopied 最终为空白。
如果我注释掉 $filesCopied = substr($filesCopied, 0, strrpos($filesCopied, " sent ")); 我会得到未格式化的整个输出。
我做错了什么?我只需要每行更改 1 个的文件。
谢谢。
【问题讨论】:
-
请张贴未格式化的输出
-
它在帖子中列出:“发送增量文件列表portalMaint.php发送27,659字节接收81字节55,480.00字节/秒总大小为101,582,367加速为3,661.95”每个空格都有一个换行符。跨度>
标签: php mariadb output shell-exec