Tuesday, November 13, 2012

Automating windows tasks for SAP systems

It always bothered me that SAP systems are so horribly bad at cleaning up after themselves. Especially anything that runs on Java, windows or is a thridparty plugin/adaptor/app/whatever.And given that I in many cases dont even have an SAP/ABAP backend to program a cleanup in, I had to make due with regular windows expressions and commands.

So the other day, when I had a javabased plugin, running on a windows system that was creating about 500 logfiles/day, I figured, enough is enough, I dont WANT anymore alerts on semifull disks, bad performance or requests for defrag etc. etc. caused by millions of small files taking up all the space on the system. 

So I decided to create a small script that would clean up all of the subfolders that contained the offending files.

I created a file called "cleanup.cmd" and placed in on the servers desktop. 
In the file, I put a lot of lines that would uniquely identify the files that I was looking for, lines like this:

forfiles /P "<absolute_path_without_wildcards>" /S /M <mask> /D -<age> /C "cmd /c echo @path"

Once each line selected the stuff I wanted from the directories (and with the /S also subdirectories) I wanted, I replaced the  "cmd /c echo @path" with "cmd /c del @path" and saved the file.

Then it's just a matter of scheduling it in the windows scheduler to run on a monthly basis.


At some point in time, I'll take the time to create a script that'll be able to accept a parameter or two so that it'll clean up each of the different types of systems I manage, that does not clean up all of its own work- and logfiles (XI, gw connector, charm, TREX, livereorg, redwood, BPC, SBOP,  sapconsole etc....). It would be so nice if I could just maintain ONE script.... Oh, the hazzards of automation :D

No comments:

Post a Comment