Sunday, January 4, 2009

Scheduling a Task on Windows Per Minutes

Such an easy on job on Linux, turned out not so on Windows XP Pro and all I wanted to do is to export a process's info to a file every 5 minutes.

The Task Scheduler of Windows doesn't show you the option to run a periodical task per minutes.

After a quick search, I found out that it can be done in the command line interface (CLI).
C:\PsTools>schtasks /Create /SC MINUTE /MO 5 /TN javawatch /TR C:\PsTools\batch.bat
The task will be created under current logged-on user name ("ADRENALIN\Administr
Please enter the run as password for ADRENALIN\Administrator: ******
SUCCESS: The scheduled task "javawatch" has successfully been created.

After this, the task will show in your graphical task scheduler program:

You can see that the 5-minute interval is hard-coded into it!

As you can see in the CLI code, I'm pointing the task at a batch file. Contents of "batch.bat":
time /t >> java_watch.log
C:\PsTools\pslist.exe -m -e java >> java_watch.log

pslist is not a standard Windows tool but can be obtained for free here. It comes along with many other useful tools so make sure you check them out.

Anyway, I used pslist to extract memory info from a process called "java" -- you could omit the -e flag and just provide the process ID (PID).

No comments: