How to do one line bash schedule task?

This seems to work: http://www.unix.com/shell-programming-scripting/179705-how-run-cygwin-bash-windows-scheduled-task.html

However, I was hoping to avoid writing a 2 line bat files to invoke my cygwin scripts as a scheduled task (since I'm making lots scheduled tasks).

I was hoping this would work:

SCHTASKS /CREATE /TN test /TR "C:\cygwin\bin\bash.exe -l -c c:/Users/siegfried/Documents/bin/test.sh >> c:/Users/siegfried/Documents/logs/test.log 2>&1" /ST 23:08 /SC daily

Unfortunately, bash seems to be ignoring my attempts to redirect stdout and stderr.

I've tried both single and double "greater than" signs to make it write to test.log and nothing seems to work. The task runs OK: I just cannot get it to make a log file for me.

The alternative, of course, is to specify the file name of a two line bat for the SCHTASKS/CREATE command and inside that silly two line at file, call c:\cygwin\bin\bash.exe. This works, but then I have to manage these two line bat files.

Thanks
Siegfried

That string is unquoted, so may not be reaching bash at all. The entire command for -c must be one paramater, and it may be taking >> and 2> as anything from shell redirects windows handles to invalid filenames. Quoting is not consistent in Windows before the shell is actually run, see.

SCHTASKS /CREATE /TN test /TR "C:\cygwin\bin\bash.exe -l -c 'c:/Users/siegfried/Documents/bin/test.sh >> c:/Users/siegfried/Documents/logs/test.log 2>&1'" /ST 23:08 /SC daily

Unfortunately this depends on the way schtasks handles quoting. The way Windows commandline programs handle quoting is not consistent and may vary from program to program. It may need ', '\, \", or may not be possible at all.

It is possible to move your shell redirects inside of test.sh instead with these lines above the code. This would mean you wouldn't need a whole extra bat file.

exec >> c:/Users/siegfried/Documents/logs/test.log
exec 2>&1