running shell script with windows task scheduler

2019-06-03 05:17发布

问题:

I currenty have a simple shell script that I created for a linux machine to be run using cron, but now I want to be able to run the file using windows task scheduler. I have tried to get it to work using cron for cygwin, but even after running cron-config successfully and ensuring that the shell script can be executed successfully, for some reason the cron task simply wasn't executing. So I decided to give in and use the windows task scheduler. In order to do this, I looked at the following posts about the issue:

Cgywin .sh file run as Windows Task Scheduler

http://www.davidjnice.com/cygwin_scheduled_tasks.html

in my case, the entry in the "actions" tab of the new task looks like this:

program/script: c:\cygwin64\bin\bash.exe

arguments: -l -c "/cygdrive/c/users/paul/bitcoinbot/download_all_data.sh >> cygdrive/c/users/paul/bitcoinbot/logfile.log 2>&1"

start in: c:\cygwin64\bin

Notice that I redirected the output of the shell script to a log file, so that I should be able to see there whether the program run. Other than that, I simply edited the "trigger" tab to run the task daily, and set the time to a couple of minutes in the fture to see whether it ran successfully.

Alas, when I look at the detailed event history for the task, nothing changes when the trigger time passes. And when I manually "run" the task, the event history seems to add a few different events, but the task is completed within seconds, whereas this task should take over an hour (and it does when the shell script is executed directly from the terminal). And when I look for the log file that should have been created, there is nothing.

Does anyone have any idea what might be the issue here? How can I get my task to run properly at the trigger time, and how can I make sure it does so?

Best,

Paul

EDIT: here are the pictures showing event history, as per Ken White's request. Please ignore the fact that it says there are 24 events. These are from multiple separate runs of the task. The events shown here are a complete list of the events triggered by a single run.

EDIT 2: Regarding my attempts to get cron to work, I have run into the following problem when I try to start the cron service using cygrunsrv. First of all, I tried to start cron by typing

cygrunsrv -I cron -p /usr/sbin/cron.exe -a -D

Now when I type

$cygrunsrv -Q cron Service: cron Current State: stopped Command: /usr/bin/cron.exe

Now, I tried to start the cron service by typing

cygrunsrv -S cron Cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started.

Does anyone hae any idea what this error means? I tried googling it, but couldn't find any answers.