📜 ⬆️ ⬇️

Deploy cron to Windows

The standard Windows scheduler is powerful, but I ran into a problem that prevented me from using it easily in the “home” edition of Windows. I had to install a real cron in the system. Not a bit sorry!
How came to this, and what from this learned under the cut.

User without rights


It all started with the fact that I wanted to schedule a task. It was necessary to execute every minute a simple cmd-script that prepared the environment and ran a certain Python script.
Since the machine on which the task is performed is not the main worker, it was necessary to carry out the task, even when the user did not log in. For this mode was selected:

When you save the job, the scheduler warned you that you must allow "Login as a batch job" for the specified user. To do this, it is proposed to change the security policy . However, this could not be done, as there is no snap-in for managing the security policy in the “home” version of Windows ( I will be grateful for the hint of an alternative solution ).
From confusing configuration it became somehow quite sad and I wanted to have a tool as simple and clear as cron ...

Cronization Windows


Installing cron on Windows turned out to be a completely realizable undertaking. I did not begin to search for a special version of cron for Windows ( share if anyone knows ), but turned right away to Cygwin . In addition to the standard package, I chose:

With the cron package everything is clear. The cygrunsrv package allows you to run various programs as a service. After installing Cygwin, you can proceed to cron configuration.

Configuring the cron service in Windows


Now go to the most important step. Run "Cygwin Terminal" with administrator rights and type the command:
> cron-config Cron is already installed as a service under account LocalSystem. Do you want to install the cron daemon as a service? (yes/no) yes Enter the value of CYGWIN for the daemon: [ ] ntsec Do you want to start the cron daemon as a service now? (yes/no) yes 
About ntsec can read more here .
')
Is done. You can give jobs. If the service did not go, try to start it manually:
 > net start cron 

Now open crontab and write tasks (vi by default):
 > crontab.exe -e 

You can “fill” the task through echo:
 > echo "*/5 * * * * /cygdrive/c/crons/task.bat" >> C:\cygwin\var\cron\tabs\[Username] 

Now reboot your computer and see how well tasks are performed without logging in.

Source: https://habr.com/ru/post/149545/


All Articles