I'm having a bit of trouble pulling certain values from a variable in my Perl script on an Ubuntu 12.04 box.
I looked over this page: How to extract string following a pattern
And this is sort of what I want to do. I need to extract a string value after a certain pattern. Here's the code I have thus far:
foreach $HDD (@sds)
{
$hdStat = `hdparm -i $HDD | grep -Po 'Model=\K.*?(?=,)'`;
$sdModel{$HDD} = $hdStat;
$hdStat = `hdparm -i $HDD | grep -Po 'SerialNo=\K.*?(?=")'`;
$sdSerial{$HDD} = $hdStat;
}
foreach $HDD (keys %sdModel)
{
print $sdModel{$HDD};
}
foreach $HDD (keys, %sdSerial)
{
print $sdSerial{$HDD};
}
It will return the Model string just fine, but it won't return the SerialNo string. The code doesn't have to be with grep; I just modified the code from the link above. And seeing as how I am terrible with regex, I'm probably missing something basic here.
Btw, the purpose of this code is to look through the /dev folder to find any disk drives, and if it does, sets it into an array, where the above script will then get it's Model # and Serial #. Also, if anyone sees a better way to do what I'm doing, I am very open to suggestions. I am still very new to Perl (only been with it about a week so far).