In this article we created archived log files. Well, it would be nice to have a way to grab the daily log files off of an HTML document. Here is a perl script that does this:
#!/usr/bin/perl for ($month=1;$month<13;$month++){ system("cal -1 $month 2003 > calout"); open(CAL, "< calout"); print "<pre>"; while (<CAL>){ $last=$_; if($last=~/[A-Z]/){ if($last=~/\d\d\d\d/){ @my=split " ",$last; print $my[0].":\n\n"; $mo=substr($my[0],0,3); } else{ $last=~s/ / /g; print $last."\n"; $grabpad="yes"; } } else{ if($grabpad == "yes"){ $last=~m/^( +)\d/; $pad=(length($1)-1)/3; for ($p=1;$p <= $pad;$p++){ print " "; } $grabpad = "no"; } @el=split " ", $last; for($i=0;$i<7;$i++){ if ($el[$i] != ""){ printf ("%02d ",$el[$i]); if ($el[$i]=~/\d\d/){ printf ("<a href=03%02d%02d.html>LOGSO</a> ",$month,$el[$i]); } else{ printf ("<a href=03%02d%02d.html>LOGSO</a> ",$month,$el[$i]); } } } print"\n"; } } print "</pre>"; close CAL; } |
See this article for a slight variation of this script and more info. For an example of the output, see this file. You have to run this on a system with cal on it. GNU/Linux or maybe even Cygwin would be fine. Of course, you can use this for anything you need a calendar format for, we just happened to need it for log files.