Invasion of the Log files!

Log files, aren’t they great? When things don’t work, they’ll let you know what’s up!

The problem with them is that in IIS, I haven’t found a setting that says only retain log files for x number of days…

So, once upon a time, my log files filled up the hard drive and the system went down. SharePoint didn’t work and thus we were not happy campers. In hindsight, I’d say “Why didn’t I set the log file location to a separate drive instead of the default system drive? Of course it’d go down when it filled up!” Who knows? Maybe I didn’t have another drive, or didn’t want to, or couldn’t make another partition for some reason?

No matter the situation. This batch file will keep things tidy. I used it to clean up both IIS and SharePoint logs (Even though SharePoint logs have decent management already). Just save it to your hard disk and schedule it as a task. I run it once a week.

This script does depend on a program called “sendemail.exe” so make sure you download that.

Resources

Code

REM This batch file cleans out error logs from SharePoint and/or IIS to prevent system outages/failures from hard disks filling up.
REM Written 8/3/2011 by Josh Martell

REM **************************Options*******************************
REM ip address or server name of smtp server
set emailserver=email server url or IP

REM FROM email address
set fromaddress=something@domain.com

REM TO email address for multiple addresses seperate with a space.
set toaddress=you@domain.com

REM Email Subject
set subject=%computername% Log Cleanup Report

REM Is the server this is running on a sharepoint server? yes/no
set sphost=yes

REM Location of SharePoint logs
set splogs=C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS

REM Location of IIS logs
set iislogs=C:\Inetpub\logs\LogFiles

REM How many days of log files do you want to keep?
set age=31

REM Backup location for upgrade.log
set BULoc=unc path for backup location

REM location of sendemail.exe
set SEloc=c:

REM ************************End_Options*****************************

set start_time=%date% %time%

IF %sphost% EQU yes (GOTO cleansp) ELSE (GOTO cleaniis)
:cleansp

REM ***Start size calculation of sharepoint log folder before cleanup***
For /F “tokens=*” %%a IN (‘”dir “%splogs%” /s /-c /a | find “bytes” | find /v “free””‘) do Set xsummary=%%a
For /f “tokens=1,2 delims=)” %%a in (“%xsummary%”) do set xfiles=%%a&set xsize=%%b
Set xsize=%xsize:bytes=%
Set xsize=%xsize: =%
set spbefore=%xsize%
set /a spbefore=%spbefore%/1024
set /a spbefore=%spbefore%/1024
REM ***End size calculation of sharepoint log folder before cleanup***

REM ***Start SharePoint Log Cleanup***
IF EXIST “%splogs%\upgrade.log” (copy “%splogs%\upgrade.log” “%BULoc%\%computername%-update.log”)
for /f “tokens=*” %%s in (‘FORFILES /p “%splogs%” /s /M *.log /d -%age% ^| find “” /v /n /c’) do set spcount=%%s
FORFILES /p “%splogs%” /s /M *.log /d -%age% /c “cmd /c del /q @file”
REM ***End SharePoint Log Cleanup***

REM ***Start size calculation of sharepoint log folder after cleanup***
For /F “tokens=*” %%a IN (‘”dir “%splogs%” /s /-c /a | find “bytes” | find /v “free””‘) do Set xsummary=%%a
For /f “tokens=1,2 delims=)” %%a in (“%xsummary%”) do set xfiles=%%a&set xsize=%%b
Set xsize=%xsize:bytes=%
Set xsize=%xsize: =%
set spafter=%xsize%
set /a spafter=%spafter%/1024
set /a spafter=%spafter%/1024
REM ***End size calculation of sharepoint log folder after cleanup***

:cleaniis

REM ***Start size calculation of IIS log folder before cleanup***
For /F “tokens=*” %%a IN (‘”dir “%iislogs%” /s /-c /a | find “bytes” | find /v “free””‘) do Set xsummary=%%a
For /f “tokens=1,2 delims=)” %%a in (“%xsummary%”) do set xfiles=%%a&set xsize=%%b
Set xsize=%xsize:bytes=%
Set xsize=%xsize: =%
set iisbefore=%xsize%
set /a iisbefore=%iisbefore%/1024
set /a iisbefore=%iisbefore%/1024
REM ***End size calculation of IIS log folder before cleanup***

REM ***Start IIS log folder cleanup***
for /f “tokens=*” %%i in (‘FORFILES /p “%iislogs%” /s /M *.log /d -%age% ^| find “” /v /n /c’) do set iiscount=%%i
FORFILES /p “%iislogs%” /s /M *.log /d -%age% /c “cmd /c del /q @file”
REM ***End IIS log folder cleanup***

REM ***Start size calculation of IIS log folder after cleanup***
For /F “tokens=*” %%a IN (‘”dir %iislogs% /s /-c /a | find “bytes” | find /v “free””‘) do Set xsummary=%%a
For /f “tokens=1,2 delims=)” %%a in (“%xsummary%”) do set xfiles=%%a&set xsize=%%b
Set xsize=%xsize:bytes=%
Set xsize=%xsize: =%
set iisafter=%xsize%
set /a iisafter=%iisafter%/1024
set /a iisafter=%iisafter%/1024
REM ***End size calculation of IIS log folder after cleanup***

set end_time=%date% %time%

REM ***Calculate Space Savings***
set /a spspacesaved=%spbefore%-%spafter%
set /a iisspacesaved=%iisbefore%-%iisafter%
set /a totsaved=%spspacesaved%+%iisspacesaved%
set /a totbefore=%spbefore%+%iisbefore%
set /a totafter=%spafter%+%iisafter%
set /a totcount=%spcount%+%iiscount%
REM ***End Calculate Space Savings***

REM ***Start Report***
echo %computername% Log Cleanup Report  > c:/SharePointLogsRemoved.txt
:times
echo ========================================================================= >> c:/SharePointLogsRemoved.txt
echo Start Time: %start_time% >> c:/SharePointLogsRemoved.txt
echo End Time: %end_time% >> c:/SharePointLogsRemoved.txt
echo ========================================================================= >> c:/SharePointLogsRemoved.txt
IF %sphost% EQU yes (GOTO spsizes) ELSE (GOTO iissizes)
:spsizes
echo *** Totals *** >> c:/SharePointLogsRemoved.txt
echo “Total Number of files removed: %totcount% ” >> c:/SharePointLogsRemoved.txt
echo “Total Space initially consumed: %totbefore% MB” >> c:/SharePointLogsRemoved.txt
echo “Total Space currently consumed: %totafter% MB” >> c:/SharePointLogsRemoved.txt
echo “Total Space saved by cleaning-up: %totsaved% MB” >> c:/SharePointLogsRemoved.txt
echo ========================================================================= >> c:/SharePointLogsRemoved.txt
echo *** SharePoint Log *** >> c:/SharePointLogsRemoved.txt
echo “Number of SharePoint log files removed: %spcount% ” >> c:/SharePointLogsRemoved.txt
echo “HDD Space initially consumed: %spbefore% MB” >> c:/SharePointLogsRemoved.txt
echo “HDD Space currently consumed: %spafter% MB” >> c:/SharePointLogsRemoved.txt
echo “HDD Space saved by cleaning-up: %spspacesaved% MB” >> c:/SharePointLogsRemoved.txt
:iissizes
echo ========================================================================= >> c:/SharePointLogsRemoved.txt
echo *** IIS Log *** >> c:/SharePointLogsRemoved.txt
echo “Number of IIS log files removed: %iiscount% ” >> c:/SharePointLogsRemoved.txt
echo “HDD Space initially consumed: %iisbefore% MB” >> c:/SharePointLogsRemoved.txt
echo “HDD Space currently consumed: %iisafter% MB” >> c:/SharePointLogsRemoved.txt
echo “HDD Space saved by cleaning-up: %iisspacesaved% MB” >> c:/SharePointLogsRemoved.txt
echo ========================================================================= >> c:/SharePointLogsRemoved.txt
REM ***End Report***

REM *** Send email ***
%SEloc%/sendemail -s %emailserver%:25 -f %fromaddress% -t %toaddress% -u %subject% -o message-file=”c:/sharepointlogsremoved.txt”

del c:/SharePointLogsRemoved.txt

Posted in Computers and Internet | Tagged , , , , | Leave a comment

SharePoint Post Tonight

I posted on the sharepoint blog tonight. Check it out there… here’s the link: http://sharepointexists.blogspot.com/2011/06/automating-sharepoint-server-warm-up.html
It’s a handy setting if you have a SharePoint server! I like to set it on every SharePoint server I set up.

Posted in Computers and Internet | Tagged , , | Leave a comment

Frugal Fix Friday: Washing Machine

The washing machine was broken. It wasn’t agitating the clothes and therefore not washing them so much as just rinsing them in water. A visit from the repairman would cost at least $60. No, thank you!

We dissected the agitator and found these little flaps with worn teeth. I later found out these are called “Agitator dogs”.

With a quick online search for our machine’s model number at Searspartsdirect.com we found the exploded diagram of our machine. Using this diagram we could identify the part number of the pieces in our hands. We looked them up and ordered replacements from Sears. It cost about 9 dollars.

A couple days later the part arrived and less than 10 minutes later the wash machine was working great!

I can’t believe we used to pay people to fix things!

I wanted to post some pictures to show where this part is, but while looking for a good pic I found this video that goes through the entire repair instead.

Posted in DIY | Tagged , , , , , | Leave a comment

Kindle Case

This weekend Amy and I made a case for my Kindle. It was an experiment and didn’t go exactly as expected. Regardless, I think it turned out good for a first try, and it does it’s job of protecting my Kindle in transit.

I’m going on vacation soon, and will be bringing my Kindle so I need a case so I don’t break it. The lighted case was $60 and it was still $40 without the light! Didn’t want to spend that much. We spent $11. $7 at Target for the leather notebook, and $4 at Michael’s for Rubber Cement, Felt, and Elastic.

Here are the pics:

Kindle case - outsideKindle Case- Inside

Posted in DIY | Tagged , , | Leave a comment

Excuses

I’m really good at coming up with excuses not to run. Like today, for example, my legs hurt and it is raining. So, I couldn’t run today; that’d be absurd.

I’m doing my warm up walk as I write this. I think it’s time to start ignoring myself. My excuses are lame.

Posted from WordPress for Windows Phone

Posted in Fitness | 1 Comment

I don’t have a post.

But this made me laugh at lunch today…

Posted in Computers and Internet | Leave a comment

$300 Car Repair for $20

Almost 2 years ago, I took my car to the local dealership/mechanic because my “check engine light” was on. They charged me over $130 just to plug in the computer and read the code! I didn’t know at the time that I could just go to any auto parts store and they would read it for free, but that’s besides the point. They told me what the error was and that it would be another $170 or so to fix it, otherwise my car would continue running fine despite the light and it might just fail to start on occasion. So if I had it fixed, it would have cost me over $300 all together. I opted to drive it with the error light.

For just $40 more than they charge to read an error code, my friend just bought a (very nice) code reader. We plugged it in the other day and saw that it was a bad “EGR Pressure Feedback Sensor”. That part can be replaced for as little as $20  and 5 minutes of your time. No tools required even! So, we swapped it out and turned off the error light. No problems since. (I paid $40 for the part, a $20 lazy tax, because a $40 model is what the local parts store had on hand and I didn’t want to wait for shipping from the online retailers. Luckily I’ve been saving $20 a week by not driving to work!)

A big thank you to my friend! I owe him lunch. 🙂

Now for that stupid window regulator…

Posted in Finances | Leave a comment

Commute Cost Calculator Edits

Just a quick update here… I tweaked the Commute Cost Calculator a tiny bit. Now the Cost of Commute column also shows how much money was saved for days that were biked. As you can see below, this is depicted by a negative dollar value. The other benefit that comes from this is that the Total Saved Biking value is much more accurate because it is calculated using the varying daily gas prices instead of the monthly average.

The newest version can be found here on my skydrive.

Posted in Finances | Tagged | Leave a comment

Updated Commute Cost Calculator

Today I updated my cost calculator to support daily gas price updates.

As you can see below, I added 2 new columns. In the gas price column, you just enter the price of gas that day when you enter your transportation mode. The second new column, Cost of Commute will calculate the cost of driving on that day.

image

Other things that were effected by this are the Average Gas Price, and the Total Cost of Driving. Average Gas Price is no longer an input because it is calculated by the numbers in the cost column. It didn’t occur to me to move it from the input section until now. Smile Total cost of driving is now calculated by the Cost column as well, instead of by the average.

The only problem I have with it right now is that the “Total Saved by Packing a lunch”, and “Total Saved by Biking” are not as accurate as the “total cost of driving” because they are still calculating by the average gas price. You can see in the example above that “Total saved by packing lunch” is 5 cents lower than the total cost, but since everyday this month that I drove, I brought a lunch, it should be the same. It’s not a huge difference now, but on the year end review these discrepancies will add up. It’s still a great visual, I think and will help me immensely.

If you only drive to work, and never drive home for lunch breaks, the “total saved by packing a lunch” figure will not matter to you anyways. I figure that’s one of the pieces of this that is kind of custom tailored to me.

My most current update of this workbook can be found here: Commute Calculator Type- Microsoft Excel Workbook Size- 119.6 KB
NOTE: This is an Excel file, and I used data validation on it so it cannot be opened on Excel web services (in your web browser). You would need to download it and use the full version of Excel. I don’t know if it will work in OpenOffice I have not tried that.

Posted in Finances | Tagged , , | Leave a comment