[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string parsing vs hddtemp question
- From: Andrew Starks <andrew.starks@...>
- Date: Sun, 17 Mar 2013 19:52:02 -0500
On Mar 17, 2013, at 19:45, Andrew Starks <andrew.starks@trms.com> wrote:
> On Mar 17, 2013, at 19:24, Laurent Faillie <l_faillie@yahoo.com> wrote:
>
>> Hello,
>>
>> A question related to file parsing that drive me nut :(
>>
>> hddtemp is a tool that is monitoring disk temperature.
>>
>> With only 1 disk, it expose following string :
>> "|/dev/sda|WDC WD5000AAKB-00H8A0|29|C|"
>>
>> and I've been successfully able to parse it with following code :
>>
>> local mnt,tp,temp,unit = string.match( s,
>> "|(/dev/%a+)|(%a.+)|(%d+)|(%a)")
>>
>> But with more disk, the string become :
>> "|/dev/sda|IBM-ESXSDTN073C1UCDY10F|28|C||/dev/sdb|WDC
>> WD3200AAJB-00J3A0|43|C||/dev/sdc|Maxtor
>> 34098H4|UNK|*||/dev/sdd|???|ERR|*||/dev/sde|???|ERR|*|"
>>
>> where sda and sdb are disk whom the temperature can be requested.
>> sdc is present on the system but it doesn't support temperature query
>> (too old).
>> sdd and sde aren't present at the moment.
>>
>> I would like to iterate against disk exposing their temperature (other
>> can be ignored) but
>> for mnt,tp,temp,unit in s:gmatch("|(/dev/%a+)|(%a.+)|(%d+)|(%a)|") do
>> print(mnt, tp)
>> end
>> miserably fails
>> /dev/sda IBM-ESXSDTN073C1UCDY10F|28|C||/dev/sdb|WDC WD3200AAJB-00J3A0
>> nil
>> so it is confused when reading first disk name.
>>
>> Any idea to parse such strings, being able to iterate b/w each disks
>> whatever the string contains 1 or more disks ?
>>
>> Thanks
>>
>> Laurent
>>
>> ps: I've been able to get the information by iterating against each
>> field using "([^|]*)" and then counting next fields to rebuild the
>> structure. But I'm looking for a more efficient solution
>
> The way you're doing it is fine and I think the way you're doing it is
> fine. Perhaps just making the pipe ?
>
> I didn't check this. The thrust of my post is really about making this
> an opportunity to check lpeg out.
>
> dev = (P"|"^-1 * "/dev/" Ct(alpha)^1 * P"|") -- etc.
>
> --Andrew
Ct should be C
But the whole thing might not work, because I'm typing this on my
iPhone, and the Mail application's debugger is horrible.
-Andrew