The Cron Service for windows has been updated. To see what we have added, visit the announcement page
If you spend any amount of time working with Unix, you will come across Cron and the CronTab file.
What is it?
Cron allows you to schedule programs to run at specified intervals, like every Sunday at 1AM.
Now I can already hear it…”Steve, that is what the task scheduler is for in Windows”
While it is true you can schedule tasks in Windows, one big issue with task scheduler is how do you transfer scheduled tasks from one computer to another?
You could copy the folder c:\windows\tasks, but this is totally unsupported and it does not always work.
That is the beauty of Cron. Every bit of scheduling info is contained within the Crontab file.
If you want a group of servers to have the same scheduled jobs, you just need to sync this file. No registry hacks, no tricks. Just one file.
Not only that, since it is just a simple text file you can easily schedule jobs from PHP, PowerShell or VBScript…without any ActiveX or hooks into Windows. You just need to modify a simple text file.
There are a few Windows implementations out there…but most of them are quite old. We wanted something that would work on 2000 through 2008 x64 – so we built our own 🙂
To use it, download the setup file from our downloads page:
http://www.intelliadmin.com/index.php/downloads/
The install does not create any icons, or shortcuts. It installs all the application files into c:\program files\IntelliAdmin\Cron
by default, and automatically starts the cron service (Named icronsvr).
The file that tells it what to do is the ‘crontab’ file. It roughly follows the same format as the Unix crontab
The file is formatted in this way:
[M] [H] [D] [M] [DOW] [Process Name] [Process Arguments]
M – The minute that the process should be executed (0-59)
H – The hour that the process should be executed (0-23)
D – The day that the process should be executed (1-31)
M – The month that the process should be executed (1-12)
DOW – The day of the week that the process should be executed (0-6 Sunday = 0, Monday = 1, Etc)
Note: Our format does not support names such as THU, or JAN…only numerical values
Each section can:
-Have a range of values like this: 12-24 (All items from 12 to 24)
-Have a list of values like this: 12,13,14,15
-Include all possible values like this: *
-Skip values using the / like this: 0-59/5 (This would only include 0,5,10,15,20,etc)
Lets put it all together. If we wanted a process to run every 5 minutes we would create a line like this in our crontab file:
*/5 * * * * "c:\windows\system32\cmd.exe" "/c c:\test.bat"
See how the skip value works? We specified the * for the minute section (All minutes), and then told it to skip 5. This means it will run at 0, 5, 10, 15, 20, etc.
If you wanted to run a process every Sunday at 1 pm:
00 01 * * 00 c:\process.bat
Or how about, only every Sunday from June to the end of the year:
00 01 * 06-12 00 "c:\windows\system32\cmd.exe" "/c c:\test.bat"
At 15, and 30 minutes past every hour:
15,30 * * * * "c:\windows\system32\cmd.exe" "/c c:\test.bat"
This might give you a clearer picture:
* * * * * C:\SomeEXE.EXE ARG1 ARG2 ARG3 - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59)
It takes a little time to get used to the format, but once you do it is a breeze to work with.
A few things to think about when using this:
-Make sure you secure the crontab file by only allowing ‘System’ and Administrator write access. Otherwise a standard user could simply alter the crontab file and start running stuff as ‘System’
-The programs are run in the context of a service. By default the user account is ‘System’, and for security reasons it does not have network share access. If you want to allow access to network shares you would have to go into the settings of the IntelliAdmin Cron Service, and have it login as a user with the appropriate rights.
-Since it is a service, make sure your program does not pop up forms or message boxes…otherwise they will just get stuck and you will never see them. Test…test…test before you deploy.
If you have any other features you would like to add to this little tool, let us know and we will see what we can do.
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools
{ 23 comments… read them below or add one }
Amazing. Thanks for sharing!
Does Windows allow something like user impersonation to be used so that you can have different crontabs for different users like in Unix and have them run in the context of that user as opposed to the System account?
Really good question Miguel. No not at this time. The problem with that under windows is that the password would have to be specified. So this would be a weak point. Still, there are some ideas we are working on ideas on how to do this elegantly.
Have you checked out macro scheduler? I have been using it for years, since version 4
Hello Michael,
Yes…have seen Macro scheduler before. In this case, it would be too much for what we wanted….and I am not sure how they store their scheduled tasks. I believe it is in the registry. The reasons we wanted to build this little cron service:
-The ability to easily synchronize the list of tasks between servers (Just copy the file)
-The ability to edit it from a web based service (Simple text editing from PHP)
-Easy backup of our list of scheduled tasks. (Just copy the crontab file)
I don’t think Macro scheduler would fit these goals – but it is a very powerful tool that does have its place. If I remember it right we used to use Macro scheduler at a bank I worked at a few years ago. It allowed us to automate the handling of the ATM data upload that required some mouse movement and clicks…which saved quite a bit of time over the years.
Great stuff. I just set this up on one of my 2003 boxes, and it works great. Thanks steve.
Glad to hear it Bobby
Your comment is awaiting moderation.
Hi there,
could not get this program to work (at least I think so). Installed it as a service and added these lines:
*/1 * * * * “echo aaa>log”
*/5 * * * * c:\process.bat
*/1 * * * * cmd
process.bat contains:
echo aaa>>D:\test.log
but none of the files are created, nor cmd is called. What behaviour should be expected here? What am I doing wrong?
Hello Rob, just saw your other message…looks like it got caught up in the spam filter.
Is there a status.log file in the same folder as the cron service? If so, does it have any entries?
OK. See the problem
With bat files you need to push them through cmd.exe like this:
*/1 * * * * "c:\windows\system32\cmd.exe" "/c c:\test.bat"
And with batch commands themselves..the same is true:
* * * * "c:\windows\system32\cmd.exe" "/c echo test >> c:\output2.txt"
Make sure you don’t forget the /c or it will leave cmd.exe running on your system forever…and they will keep piling up…hidden
With regard to impersonation, take a look at TqcRunAs.exe by Quimeras.
In your examples you wrote that
*/5 * * * * c:\process.bat
will work.
After Rob asked for help because he can´t get that runing you
answered that batch files won´t work that way and the right syntax is:
*/1 * * * * “c:\windows\system32\cmd.exe” “/c c:\test.bat”
Completely different. I am confused.
i installed the service, setup an entry in the crontab file, but am not sure if my task kicked off.
i do not see a status.log file in the directory where my crontab lives. is that where it goes?
also is the crontab dynamically changeable or must the Cron Service be restarted after changing the CronTab file?
Thanks.
Hello Peter,
You are right…those examples are wrong. I have corrected the article.
Also, Next week we will try to put this program through some more testing to see if there are any issues…it seems like some are reporting that it is not working. I will post updates as comments on this article
Just wanted to keep everyone who is still reading this up to date:
We are actively working on the cron application and should have a new version out soon.
Some things that we will add:
-Better logging so you can see if an app ran or not
-Automatic handling of VBS and BAT files so you don’t have to worry about putting cmd.exe or cscript.exe in the command line
I will update this post when we release it…should not be too long
Almost complete with the update. This version will also include the ability to launch into the users session…and even remote desktop sessions.
I saw a message from someone waiting for the updates…sorry but a server issue blew the comment away…so I apologize for that.
The update should be out this week…if all of our testing goes well
Hello Folks,
If you are still reading…The new version is completed. You can just go to the downloads section and get a copy.
Here is the link to the article about the new version:
http://www.intelliadmin.com/?p=5079
Just installed and tested. Below are the entries from status.log; neither FF nor NotePad actually launched:
[2012/10/18 – 17:11:00] Executed [C:\Program Files\Mozilla Firefox\firefox.exe] with arguments [] Session ID: 0 Return Code: 1
[2012/10/18 – 17:18:00] Executed [C:\windows\system32\notepad.exe] with arguments [] Session ID: 0 Return Code: 1
Looks like you did not provide any session options. I see it says session 0, which means you are trying to launch into the service session…it can’t do that.
Set the entry to launch into the current console session and it should work.
I installed and its working fine. When calling the exe from network path, it is not working and it says does not exist even the file is there.
*/5 * * * * “//172.16.1.5/test/test.exe”
[2013/02/05 – 21:01:00] Could not execute the file [//172.16.1.5/test/test.exe] because it does not exist
Thanks
Hello,
Due to the windows security model you can’t access windows shares from the system account…which means you can use them for the cron config file…and that is why it does not work.
The answer to this is to allow the file to include username/password account information…but at this time we feel it is too risky and have not found a solution we are comfortable with yet.
Doesn’t this really do the same as the built in “at” command in Windows???