Created
September 14, 2022 12:12
-
-
Save kchiem/a7590143a27a44bd78a6b0251219e50d 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
## main () | |
my %gpt_map = get_gpt_map(); | |
while (my $line = <STDIN>) { | |
$line =~ s{(gpt(?:id)?/\S+)}{ | |
my $k = $1; | |
my $l = length ($k); | |
my $v = exists $gpt_map{$k} ? $gpt_map{$k} : $k; | |
sprintf("%-${l}s", $v); | |
}egx; | |
print $line; | |
} | |
## subroutines | |
sub get_gpt_map { | |
my %map; | |
open(GLABEL, "/sbin/glabel status |") or die $!; | |
while (my $line = <GLABEL>) { | |
chomp $line; | |
if ($line =~ m%\s*(\S+)\s+(\S+)\s+(\S+)%) { | |
my ($id, $status, $component) = ($1, $2, $3); | |
next if $id eq 'Name'; | |
$map{$id} = $component; | |
} | |
} | |
close(GLABEL); | |
return %map; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ zpool status | glabel-map