Running CYGWIN scripts as a scheduled task in Windows

CYGWIN has many utilities you can install to make life as a UNIX administrator more homely within a Windows environment, but the one thing it is lacking is the ability to run scheduled tasks (cron).

To run a cygwin script (or executable?) from the Windows Task Scheduler, perform the following:

  1. Open the Windows Task Scheduler, e.g., search for “task scheduler” from the Windows start menu.
  2. In the left-hand pane, select Task Scheduler Library or, optionally, select one of its subfolders, creating one if desired. (I keep my tasks under a personal subfolder I've created, for easy reference.)
  3. Select menu item Action: Create Task...
  4. Enter a task name in the Name: field.
  5. (optional) Enter a description in the Description field.
  6. Other things in this tab can be left as-is, although I generally choose Run whether user is logged on or not.
  7. Skipping over the Triggers tab for now, select the Actions tab.
  8. Push the New... button.
  9. Make sure Action is “Start a program”; enter the full Windows path to bash.exe (when scheduling bash scripts) into the Program/script box:
    D:/cygwin/bin/bash.exe
  10. In the Add arguments box, enter “-l -c” and the bash command to run, e.g.,:
    -l -c "/home/martinch/scripts/nwreport.ksh 2>&1 >> nwreport.log"
  11. In this example,
    • stdout and stderr are appended to the nwreport.log file in the user's $HOME directory.
    • The script runs in the user's usual bash environment; one can redirect output to local files, etc.
  12. Go back to the Triggers tab and specify when the script should be run.