# Request a file name. Assume success. set fileName [tk_getOpenFile] set if [open $fileName r] set data [read $if] close $if for {set i 0} {$i < 24} {incr i} { lappend countList 0 } set usedPIDs {} # Split on newlines to create a list of lines foreach line [split $data \n] { # Use lsearch to see if the cmd is an 'sshd' message if {[lsearch $line sshd*] == 4} { # Grab the first 5 fields in the line and save the values in # separate variables lassign $line mon day time sys cmd # Split the time into hour, minutes and seconds lassign [split $time :] hr min sec # Split the cmd on the [ to get the pid portion of the cmd lassign [split $cmd \[] name pid # If this pid is not in our list of PIDs we've used, add it # to the list of used PIDs and update the appropriate count if {[lsearch $usedPIDs $pid] < 0} { lappend usedPIDs $pid scan $hr %d hr set count [lindex $countList $hr] incr count lset countList $hr $count } } } puts $countList for {set i 0} {$i < 24} {incr i} { set count [lindex $countList $i] label .l_$i -text $i label .lcount_$i -text $count -anchor w grid .l_$i .lcount_$i -sticky w }