Last active
October 1, 2015 00:17
-
-
Save gfjardim/7e305d908a21eaea9460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function listDir($root, $filter=null) { | |
$iter = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($root, | |
RecursiveDirectoryIterator::SKIP_DOTS), | |
RecursiveIteratorIterator::SELF_FIRST, | |
RecursiveIteratorIterator::CATCH_GET_CHILD); | |
$paths = array(); | |
foreach ($iter as $path => $fileinfo) { | |
if ($filter && is_bool(strpos($path, $filter))) continue; | |
if (! $fileinfo->isDir()) $paths[] = $path; | |
} | |
return $paths; | |
} | |
$disks = preg_grep("#wwn-|-part#",listDir("/dev/disk/by-id"), PREG_GREP_INVERT); | |
foreach ($disks as $disk) { | |
$attrs = parse_ini_string(shell_exec("udevadm info --query=property --name=".realpath($disk)." 2>/dev/null 2>/dev/null")); | |
$path = dirname(dirname(dirname($attrs['DEVPATH']))); | |
$data[$path] = $attrs['ID_SERIAL_SHORT']; | |
} | |
natsort($data); | |
$max = max(array_map('strlen', $data)) + 1; | |
foreach ($data as $path => $serial) { | |
echo str_pad($serial, $max)."<=> {$path}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment