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:
- Open the Windows Task Scheduler, e.g., search for “task scheduler” from the Windows start menu.
- 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.)
- Select menu item Action: Create Task...
- Enter a task name in the Name: field.
- (optional) Enter a description in the Description field.
- Other things in this tab can be left as-is, although I generally choose Run whether user is logged on or not.
- Skipping over the Triggers tab for now, select the Actions tab.
- Push the New... button.
- 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
- 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"
- 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.
- Go back to the Triggers tab and specify when the script should be run.