Posts

Showing posts with the label cmd

Delete files older than x days using batch script

This one keeps coming back when you are administering several systems which are all pushing out some files to storage for example OLD SQL servers who are spitting out BAK files. Forfiles /P D:\SQLbackup /S /M *.BAK /D -2 /C "cmd /c del /q @path" Forfiles is standard included in windows since Windows 2000 Let me explain the switches I used. /P |This one is for specifying the path. /S |This is the same as in the dir command for recursively enumerating the files. /M |Where you specify the search pattern to look for. /D -2 |This is the most interesting part beacause this switch looks for files older or equal than 2 days. /C |Here is where you specify what to do. If you want to start a command make sure it starts with cmd /c, I did a del command specifying the file by using the @path variable.

Starting a CMD prompt hidden for cacti poller.php

After implementing a CACTI monitoring environment at our customer on a windows platform (huh). We had a problem that our CACTI poller scheduled task was visible when it was started. I first created this vbscript. To start the commandprompt hidden. Set WshShell = WScript.CreateObject("WScript.Shell") Set WshExec = WshShell.Exec("php c:\Apache2\htdocs\cacti\poller.php") But this method is much better. Because it fits on 1 line! CreateObject("Wscript.shell").run "php c:\Apache2\htdocs\cacti\poller.php",0 In short to run the cacti poller hidden you only have to schedule the above line in a vbscript every 5 minutes.