Q:

SLURM reservation output parsing

I'm looking for some help with parsing 'Duration' from output from scontrol
1
scontrol show res root_89
ReservationName=root_89 StartTime=2012-11-07T14:22:21 EndTime=2012-11-08T16:22:21 Duration=02:00:00
   Nodes=host NodeCnt=1 Features=(null) PartitionName=(null) Flags=SPEC_NODES
   Users=root Accounts=(null) Licenses=(null) State=ACTIVE

2
scontrol show res root_95
ReservationName=root_95 StartTime=2013-02-06T16:00:00 EndTime=2013-02-10T06:40:00 Duration=3-14:40:00
    Nodes=host NodeCnt=1 Features=(null) PartitionName=(null) Flags=SPEC_NODES
    Users=root Accounts=(null) Licenses=(null) State=INACTIVE

As you can see if reservation is really long Duration output is messed up And i'm looking for format 'xxHH:mm:ss'

A:

this line should work for your case:
grep -Po "(?<=Duration=)[0-9-:]*" <yourFile>|awk -F'-' 'NF==2{split($2,t,":");t[1]+=($1*24);print t[1]":"t[2]":"t[3];next;}1'

Note that I was a bit lazy, so I used grep to filter out the duration value. it could be done with awk, to save a process. if performance is not the problem in your case, you can keep the grep there.
test
kent$  cat example
scontrol show res root_89
ReservationName=root_89 StartTime=2012-11-07T14:22:21 EndTime=2012-11-08T16:22:21 Duration=02:00:00
   Nodes=host NodeCnt=1 Features=(null) PartitionName=(null) Flags=SPEC_NODES
   Users=root Accounts=(null) Licenses=(null) State=ACTIVE

scontrol show res root_95
ReservationName=root_95 StartTime=2013-02-06T16:00:00 EndTime=2013-02-10T06:40:00 Duration=3-14:40:00
    Nodes=host NodeCnt=1 Features=(null) PartitionName=(null) Flags=SPEC_NODES
    Users=root Accounts=(null) Licenses=(null) State=INACTIVE

kent$  grep -Po "(?<=Duration=)[0-9-:]*" example|awk -F'-' 'NF==2{split($2,t,":");t[1]+=($1*24);print t[1]":"t[2]":"t[3];next;}1'
02:00:00
86:40:00

