Auto-combine logfiles ([name].log, [name].1.log... - 15/01/07 06:04 AM
Okay, mIRC's logging system ends up creating a few files for each week, like "[name].log, [name].1.log, etc...". I've already written the script to sort the logfiles in a window based on the date at the top (and filename).
I'm trying to write a script that will combine all the logs for a given week and delete the extra temporary logs ([name].2.log), just to tidy up (and for the sake of my original logfiles alias). However, it's... um... not working. When it does loop, it starts to pick up the right groups of files but then just stops. The part I tacked on to the alias below is pretty messy, but maybe you can see where I went wrong. I was just trying to patch it up any whichway.
I'm trying to write a script that will combine all the logs for a given week and delete the extra temporary logs ([name].2.log), just to tidy up (and for the sake of my original logfiles alias). However, it's... um... not working. When it does loop, it starts to pick up the right groups of files but then just stops. The part I tacked on to the alias below is pretty messy, but maybe you can see where I went wrong. I was just trying to patch it up any whichway.
Code:
alias logfiles { if ($window(@Logfile).font) { window -c @Logfile | return } if ($window(@Logfiles).font) { window -c @Logfiles | return } /window -c @Logfiles | window -c @Logfile if ($1 == combine) /window -h @Logfiles else /window -lex @Logfiles /var %loop = 1, %file while (1) { %file = $findfile($qt($logdir),*.log,%loop) if (!%file) break aline @Logfiles %file inc %loop } /filter -awwc @Logfiles @Logfiles logsort if ($1 != combine) halt /window @test %loop = 1 /var %last_files, %loop2 = 1 while (1) { %loop2 = 1 %file = $line(@Logfiles,%loop) aline @test === lastfile: %last_files /// file : %file if (!%file) break ;$gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46) if (($gettok(%file,1-3,46) != $gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46)) && ($numtok(%last_files,183) > 1)) { /window -h @combo_wid while (%loop2 <= $numtok(%last_files,183)) { /var %temp = $qt($line(@Logfiles,$gettok(%last_files,%loop2,183))) /filter -fw %temp @combo_wid inc %loop2 } /write -c $+($gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46),.log) $chr(32) /filter -wf @combo_wid $+($gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46),.log) /window -c @combo_wid aline @test ===Did something! unset %last_files goto next } if ($gettok(%file,1-3,46) != $gettok($line(@Logfiles, $gettok(%last_files,1,183)),1-3,46)) unset %last_files %last_files = %last_files $+ %loop $+ $chr(183) :next inc %loop } unset %last_files /echo -gst DONE! } alias logsort { if ($gettok($1,1,46) != $gettok($2,1,46)) return $iif($gettok($1,1,46) < $gettok($2,1,46),-1,1) if ($ctime($gettok($read($qt($1),2),3-,32)) != $ctime($gettok($read($qt($2),2),3-,32))) return $iif($ctime($gettok($read($qt($1),2),3-,32)) < $ctime($gettok($read($qt($2),2),3-,32)),-1,1) ;if ($file($qt($1)).mtime != $file($qt($2)).mtime) return $iif($file($qt($1)).mtime > $file($qt($2)).mtime,1,-1) return 0 } menu @Logfiles { dclick:{ window -ex @Logfile filter -cfw $qt($sline(@Logfiles,1)) @Logfile * window -c @Logfiles } }