#!/usr/bin/perl # # 更新履歴のグラフを出力 # 月初めに実行させる # ### 設定 ### # gnuplot のパス $gnuplot = '/home/yosh/bin/gnuplot'; # 出力先画像 $pngfile = '/home/yosh/www/accesslog.png'; # ログデータ $logfile = '/home/yosh/www/accesslog.txt'; # アクセスログのあるディレクトリ $accpath = '/home/yosh/www/cgi-bin/acc/logs/'; # gnuplot 設定ファイル $pltfile = 'accesslog.plt'; ### メイン ### # 先月の年月を取得 ($month, $year) = (localtime(time))[4,5]; $year += 1900; if ($month == 0) { $month = 12; $year--; } &makeLogFile($year, $month); &makePltFile($year, $month); system("$gnuplot $pltfile"); unlink($pltfile); exit; ### ログファイルを生成 ### sub makeLogFile { my ($year, $month) = @_; my $cnt=0; my $source = sprintf("%saccess_log.%4d%02d00.cgi", $accpath, $year, $month); open(ACC, "$source") || die; while () { $cnt++; } close(ACC); open(LOG, ">>$logfile"); print LOG "$year/$month\t$cnt\r\n"; # 一応CR+LF close(LOG); } ### pltファイルを作成 ### sub makePltFile { my ($year, $month) = @_; my $linenum = ($year-2004)*12 + $month - 5; my $line, $year=0; my $temp, $label = "\"'04/5\" 0"; $line = $linenum + 5; while ($line>12) { $year++; $temp = sprintf("\"'%02d/1\" %d", $year+4, $year*12 -4); $label .= ", $temp"; $line -= 12; } if ($line!=1) { $temp = sprintf("\"'%02d/%d\" %d", $year+4, $line, $linenum); $label .= ", $temp"; } open(PLT, ">$pltfile") || die; print PLT <