WinBlogs

Some techy stuff and occasional verbose ramblings :D

IIS server, Windows and Powershell

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 Comments

  1. Jim

    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. Alesandro Slepčević

    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. Alesandro Slepčević

    Here you go, download it from here and try it out – http://www.winblogs.net/awstats.zip . I tried it and everything works normally on my machine.

  4. Jim

    It is working “beautifully” now. Thanks this is very helpful…..

  5. Kimmi

    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 🙁

  6. Alesandro Slepčević

    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.

  7. Kimmi

    Many thanks Alesandro, it worked like charm 🙂

  8. binary

    “Your old logs! I want them!!!” EPIC! Thanks for the laugh!

  9. Rich

    Just wanted to thank you for your brilliant script 🙂

  10. Alesandro Slepčević

    You’re welcome. I’m really happy it helped you 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Theme by Anders Norén