<?php header('Content-Type: application/json'); // Передаем параметры lsblk напрямую в бинарник $command = 'sudo /usr/bin/lsblk -d -n -o NAME,SIZE,MODEL'; exec($command, $output, $return_var); $disks = []; if ($return_var === 0) { foreach ($output as $line) { // Очищаем лишние пробелы и разносим элементы по переменным одной командой $line = preg_replace('/\s+/', ' ', trim($line)); list($name, $size, $model) = explode(' ', $line, 3) + [null, null, 'Unknown Drive']; // Фильтруем виртуальные CD-ROM приводы и LiveCD образы if (strpos($name, 'sr') === 0 || strpos($name, 'loop') === 0 || strpos($name, 'airootfs') === 0) { continue; } $disks[] = [ 'name' => $name, 'size' => $size, 'model' => $model ]; } } echo json_encode(['success' => true, 'disks' => $disks], JSON_UNESCAPED_UNICODE); ?>