Difference between revisions of "Cygwin"

From dbawiki
Jump to: navigation, search
(Created page with "===How to run a crontab in Cygwin on Windows=== * Install cygrunsrv and cron packages from the admin bundle (with 'Install from internet" option) * From a Cygwin prompt, type:...")
 
(How to run a crontab in Cygwin on Windows)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
===How to run a crontab in Cygwin on Windows===
 
===How to run a crontab in Cygwin on Windows===
 +
Just to mention first that you could bypass cron altogether with this little trick:<br />
 +
Create a scheduled task with the windows scheduler by calling the shell program
 +
<pre>
 +
C:\cygwin\bin\bash.exe -l -c /cygwin/path/to/shell
 +
</pre>
 +
'''otherwise...'''
 
* Install cygrunsrv and cron packages from the admin bundle (with 'Install from internet" option)
 
* Install cygrunsrv and cron packages from the admin bundle (with 'Install from internet" option)
* From a Cygwin prompt, type:
+
* From a Cygwin prompt, to install the cron daemon as a service type:
 
<pre>
 
<pre>
 
cygrunsrv --install cron --path /usr/sbin/cron --args -n
 
cygrunsrv --install cron --path /usr/sbin/cron --args -n
Line 13: Line 19:
 
cygrunsrv --start cron
 
cygrunsrv --start cron
 
</pre>
 
</pre>
or don't use cron at all!<br />
+
Now change the properties on the service to run as a user other than "Local System"
Create a scheduled task with the windows scheduler by calling the shell program
+
====Configure cron====
 +
Run this from a Cygwin terminal
 
<pre>
 
<pre>
C:\cygwin\bin\bash.exe -l -c /cygwin/path/to/shell
+
cron-config
 
</pre>
 
</pre>
====Configure cron====
+
Show system log of possible problems from the cron daemon (service)
Run
 
 
<pre>
 
<pre>
cron-config
+
/usr/bin/cronevents
 
</pre>
 
</pre>
from a Cygwin terminal
+
 
====Diagnose problems====
+
===Diagnose problems===
 
Check installed modules
 
Check installed modules
 
<pre>
 
<pre>
Line 33: Line 39:
 
cygrunsrv -Q cron
 
cygrunsrv -Q cron
 
</pre>
 
</pre>
Show system log of possible problems from the cron daemon (service)
+
If you get
 
<pre>
 
<pre>
/usr/bin/cronevents
+
(CRON) error (can't switch user context)
 
</pre>
 
</pre>
 +
this means that the cron service is trying to run jobs as the "Local System" account. Right-click on the service and change the user it runs jobs as to be the one you want.

Latest revision as of 15:05, 4 May 2015

How to run a crontab in Cygwin on Windows[edit]

Just to mention first that you could bypass cron altogether with this little trick:
Create a scheduled task with the windows scheduler by calling the shell program

C:\cygwin\bin\bash.exe -l -c /cygwin/path/to/shell

otherwise...

  • Install cygrunsrv and cron packages from the admin bundle (with 'Install from internet" option)
  • From a Cygwin prompt, to install the cron daemon as a service type:
cygrunsrv --install cron --path /usr/sbin/cron --args -n
  • Start the cron daemon from a Windows prompt with:
net start cron

or from a Cygwin prompt with:

cygrunsrv --start cron

Now change the properties on the service to run as a user other than "Local System"

Configure cron[edit]

Run this from a Cygwin terminal

cron-config

Show system log of possible problems from the cron daemon (service)

/usr/bin/cronevents

Diagnose problems[edit]

Check installed modules

cygcheck.exe -c

Check current status

cygrunsrv -Q cron

If you get

(CRON) error (can't switch user context)

this means that the cron service is trying to run jobs as the "Local System" account. Right-click on the service and change the user it runs jobs as to be the one you want.