我來自 cmd 輸出的文本是這樣的:
pool: pool0
state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
the pool may no longer be accessible by software that does not support
the features. See zpool-features(5) for details.
scan: scrub repaired 0B in 01:24:15 with 0 errors on Sun Nov 14 01:48:17 2021
config:
NAME STATE READ WRITE CKSUM
pool0 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sda ONLINE 0 0 0
sdb ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
errors: No known data errors
我想提取池、狀態、狀態、操作、掃描、配置和錯誤的值。我嘗試使用正則運算式 gen/test 端,如https://regexr.com/或https://regex101.com/。在那里我得到了我的匹配項和池示例的“名稱”組中的值,但在 shell 中我什么也看不到
use IO::Socket::INET;
my $strCmdErg = `/sbin/zpool status`;
my $poolname= $strCmdErg=~ /pool:\s(.*$)/gm;
print "PoolName: $poolname \n";
my $state = $strCmdErg=~ /\sstate:\s(.*$)\n/gm;
print "Status: $state \n";
輸出
PoolName: 1
Status: 1
我認為“一”是匹配的指標。
謝謝!
uj5u.com熱心網友回復:
這種人類可讀的輸出可以split很容易地決議為散列。
use strict;
use warnings;
use Data::Dumper;
my $data = do { local $/; <DATA> }; # slurp text into variable
my
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/372266.html
