perl hash of arrays issue -
I have a few lines in your array is @lines where * I displays a command (such as start time sync / fetch) and the same process ID pid and shows no * command, show me the end of time they will not always be constant I would like to get a special processID and cmd to get the startdate and enddate . As UserA cmd Sync started with processID 11,859 2015/01/13 13: 53: 01.491-05 for : 00 and end 2015/01/13 13: 55: 01.492-05: 00
Below is my viewpoint in which I took a hash of the head and the ProcessID was divided as key lines are beginning to command when it works properly and end Panktian constant, but I do it how I, when they continued not.
My% Users; My $ line foreach (@lines) {if ($ line = ~ meter {(\ *) +}) {($ stdate, $ sttime, $ PID, $ user, $ cmd) = partition ', $ line; $ Startdet = "$ stdate $ sttime"; } Other {($ eddate, $ edtime, $ pid, $ user, $ cmd) = partition '', $ line; $ Enddate = "$ eddate $ edtime"; } $ User {$ pid} = [$ startdate, $ ended, $ user, $ cmd]; } content in:
2015/01/13 13: 53: 01.491-05: 00 11,859 UserA * Sink_kand 7f1f9bfff700 10.101.17.111 2015/01/13 13: 57: 02.079-05: 00 11863 UserB * Fetc_kand 7f1f9bfff700 10.101.17.111 2015/01/13 13: 59: 02.079-05: 00 11863 UserB Fetch_kand 7f1f9bfff700 10.101.17.111 2015 / 01/13 13: 55: 01.492-05: 00 11,859 UserA sync_cmd 7f1f9bfff700 10.101.17.111
I am looking at your code and wondering why you are using a hash of the array
As far as I am concerned, the object of the array is the same but one of the ordered values Set up.
Can not you do this instead:
My% processes; Forex Currency (@line) {My ($ date, $ time, $ pid, $ user, $ cmd, @ everything_lays) = split; If ($ CMD = ~ M / ^ \ * /) {#if the command starts with one - it started. If ($ procedures defined {$ pid}) {Print "Warning: $ pid reused \ n"; } $ Procedures {$ pid} {'start_date'} = $ date; $ Procedures {$ pid} {'time'} = $ time; $ Procedures {$ pid} {'users'} = $ user; $ Procedures {$ pid} {'cmd'} = $ cmd; } And {#cmd does not start with '*' ($ procedures {$ pid} {'cmd'} = ~ m / $ cmd /) {#this works because 'some_command' 'some_command' Has a substrate of $ processes {$ pid} {'end_date'} = $ date; $ Procedures {$ pid} {'end_time'} = $ time; } Else {print} "Warning: $ pid $ cmd is the command, where this $ processes {$ pid} {'cmd'} \ n"; }}} If you want to have some additional verification tests, if you have an example log in for a long time, which is reused, or eg. You have got a log that does not have any special process started and ended.
Comments
Post a Comment