Parse old log files with Awstats

From time to time I need to import old log files from IIS to our statistics software ( Awstats ) and pretty often I need to do that with lots of .log files. Instead of doing it manually, I wrote a really simple script that will do that for us.

 

BEFORE runing the script be sure to delete old Awstats data from your data folder ( usually C:\awstats\data ). Delete the files only for the website you’re updating; not all of them.

When you run the script, you will have to write the path to the folder where you keep your log files. After that you need to enter the EXACT website name.

Function Awstats
{
param ($Dir = $(Read-host "Enter path to log file")),
($Website = $(Read-Host "Website name ( without www )?"))
$TargetFolder = $Dir
if (Test-Path $TargetFolder)
{
Write-host "Folder name is :" $TargetFolder -foregroundcolor "Red"
$Files = get-childitem $Dir\*.* -include *.log
$List = $Files | where {$_.extension -eq ".log"}
foreach ($File in $Files)
{
write-host "Updating statistics! Please wait." -foregroundcolor "Red";&'C:\perl\bin\perl.exe' awstats.pl config=$Website logfile=$File}
}
Else
{Write-Host "Folder $TargetFolder doesnt exist! Input correct path!" -foregroundcolor "Red"}
}
Awstats

Do I need to point out that you will have to change the path to your perl.exe? 🙂
Also, dont forget to place the script in the same folder where your awstats.pl is!

You can download the script from this link

If you have any questions, feel free to contact me.
Bye

10 thoughts on “Parse old log files with Awstats

  1. This looks promising, but I receive the following output when I run it:

    C:\inetpub\wwwroot\AWStats\cgi-bin>LogScript.pl
    Bareword found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 3, near “$(Read”
    (Missing operator before Read?)
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 3, near “host “Enter path t
    o log file””
    (Do you need to predeclare host?)
    Bareword found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 4, near “$(Read”
    (Missing operator before Read?)
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 4, near “Host “Website name
    ( without www )?””
    (Do you need to predeclare Host?)
    Scalar found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 5, near “)
    $TargetFolder”
    (Missing semicolon on previous line?)
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 8, near “host “Folder name
    is :””
    (Do you need to predeclare host?)
    Scalar found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 8, near “”Folder name is :”
    $TargetFolder”
    (Missing operator before $TargetFolder?)
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 8, near “foregroundcolor “R
    ed””
    (Do you need to predeclare foregroundcolor?)
    Scalar found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 9, near “$Files”
    (Missing semicolon on previous line?)
    Backslash found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 9, near “$Dir\”
    (Missing operator before \?)
    Bareword found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 11, near “$File in”
    (Missing operator before in?)
    Warning: Use of “write-host” without parentheses is ambiguous at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13
    .
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13, near “host “Updating st
    atistics! Please wait.””
    (Do you need to predeclare host?)
    String found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13, near “foregroundcolor ”
    Red””
    (Do you need to predeclare foregroundcolor?)
    Backslash found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13, near “perl64\”
    Backslash found where operator expected at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13, near “bin\”
    syntax error at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 3, near “$(Read”
    syntax error at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13, near “&’C:”
    Bad name after exe’ at C:\inetpub\wwwroot\AWStats\cgi-bin\LogScript.pl line 13.

  2. It looks like the script fell apart when you copied it. Give me couple of mins and I will update the post with the download link .

  3. Hi Alesandro,

    i downloaded this script, on command line i tried to run it but cud not,Please tell me how to run it, i was doing

    C:\inetpub\awstats\cgi-bin>awstats.ps1
    and
    C:\inetpub\awstats\cgi-bin>awstats.pl -config=awstats.ps1

    but no succes please help 🙁

  4. Hi, you need to download the script, open powershell, position yourself in the folder where you saved the script, write ./awstats.ps1 and press enter. Rest of the stuff is pretty much simple.

Leave a Comment

Your email address will not be published. Required fields are marked *