Skip to content

Instantly share code, notes, and snippets.

@kchiem
Created September 14, 2022 12:12
Show Gist options
  • Save kchiem/a7590143a27a44bd78a6b0251219e50d to your computer and use it in GitHub Desktop.
Save kchiem/a7590143a27a44bd78a6b0251219e50d to your computer and use it in GitHub Desktop.
#!/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;
}
@kchiem
Copy link
Author

kchiem commented Sep 14, 2022

$ zpool status | glabel-map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment