AW stats Output log files
Hello all,
I have been writing a powershell script that reads monthly IIS logs from a folder and generates AWstats output files. The IIS log files are named in chronological order ( by date)
This is my bit of code so far
$Dir = "F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept"
$Files = get-childitem $Dir\*.* -include *.txt
$List = $Files | where {$_.extension -eq ".txt"}
foreach ($File in $Files)
{
perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File}
This currently writes to host but I would like to Output each file in the monthly folder to an output file , the output folder using name convention "*Month* run *day*.txt" For example , for September 1st.. "Septrun1" , September 2nd "Septrun2"
The month can be a variable from the Input folder (F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept)
Any advice on how I can best achieve this?
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
rileyz
8 years ago
Need more information about the folder structure, as we need that to create the output file, but you could do something like this.
Comment out the bits to test one or the other. I think the below will not output to console as its being piped. If you need to show on screen and output you could run the command twice. Ie Once to show on screen, then second to bash to file.
Not sure what your doing with $List, assume your doing something else later in the script with it.
The output file name could be better, but without knowing your file structure, its hard to create this file mask.
$Dir = "F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept"
$Files = get-childitem $Dir\*.* -include *.txt
$List = $Files | where {$_.extension -eq ".txt"}
Foreach ($File in $Files)
{#Prep output filename
$OutputFileName = $File.BaseName + '_ProcessedLog.log'
#Try this first, not sure if it will show on screen while it pipes.
& perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File | Out-File "$Dir\$OutputFileName"
#Try this second
$ProcessedLog = & perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File
$ProcessedLog | Out-File "$Dir\$OutputFileName"}
Posted by:
TonyFishers
8 years ago