Archive

Posts Tagged ‘Batch Script’

Windows – Delete Old Files

October 8, 2008 scripthacks 1 comment

A few cautionary warnings… this script will delete files from whatever location you specify as LOGPATH.  Use with care. As a best practice I always create my logs with a pre-fix. ex: CheckUpTime-.log which can then be used in the deletion script. This will ensure that you only delete logs that start with “CheckUpTime”. 

:: Delete log files older then 14 days
set LOGPATH=C:Logs

:: Echo’s logs which will be deleted (use this before using the command which contains “del”)
forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c echo 0×22@Path@File0×22″

:: Actual Delete Command (remove :: to run command)
::forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c del /q @path”

Windows Host Up Time

September 16, 2008 scripthacks Leave a comment

Find out when a Windows host was last restarted using native windows commands.  

Run net stats srv
Server Statistics for \LAP1

Statistics since 9/16/2008 9:14 AM

Sessions accepted 1
Sessions timed-out 0
Sessions errored-out 0

Kilobytes sent 0
Kilobytes received 0

Mean response time (msec) 0

System errors 0
Permission violations 0
Password violations 0

Files accessed 0
Communication devices accessed 0
Print jobs spooled 0

Times buffers exhausted

Big buffers 0
Request buffers 0

 

The command completed successfully.

Pipe to findstr to filter out unecessary stats.

net stats srv | findstr “since”
Statistics since 9/16/2008 9:14 AM