After repeated problems setting up crond to run in cygwin (it just doesn’t like the user accounts, no matter how enthusiastically I argue that I’m me), I spent some time figuring out how to run a Cygwin command as a scheduled task from Windows.
Based on this mail archive post, I created the following cygrun.bat file:
@echo off rem set HOME=c:\ if "%DEF_PATH%"=="" set DEF_PATH=%PATH% set PATH=c:\cygwin\bin;%DEF_PATH% set myargs=%* if "%myargs%" == "" goto noarg rem echo %myargs% bash --rcfile "%HOME%/.bashrc" -i -c "%myargs%" c: rem pause sleep 1 goto exit :noarg rxvt -e /usr/bin/bash --login -i :exit exit |
Then I tested the script from the command line as follows, until I had the syntax just so:
c:
cd \cygwin
cygrun.bat cygwin_script arg1 arg2 |
Once I was able to run it happily, I added the scheduled task as follows:
Run: C:\WINDOWS\system32\CMD.EXE /x /c start "Some title" /min c:\cygwin\cygrun.bat cygwin_script arg1 arg2 Start In: c:\cygwin <-- must be a real disk drive and path Run as: domain\username |
Unfortunately, I was never able to figure out how to redirect stdout and stderr. I tried plenty of variations on “>> /some/path/to/log.txt 2>&1″ with no joy. Instead, I just changed all the commands in the script and added that line on to each echo statement. Sad, but functional.