1

I'm trying to run a batch script, that copies files from the local Windows server to a remote Linux server (utilising rsync and Cygwin), as a scheduled task.

If I run the batch script manually as an admin (Run as administrator) the batch script executes successfully, and the target files are copied to the remote server.

If I run the batch script manually, without elevated privileges, only part of the batch script runs. The rsync part of the batch script fails.

So, I've setup a scheduled task. The user is a member of the Domain Admins group, and the task also has the "Run with highest privileges" option checked.

However, when I run the task through Scheduled Tasks it achieves the same as when I run the batch script manually without admin privileges but I can't figure out why.

What does Scheduled Tasks do to the User that might stop the rsync part of the batch script from executing?

To add clarification, all resources that the script utilises are local except for the remote server. The remote server is specified in the rsync command as an IP address: username@ipaddress:/remotedirectory/

Additionally, I should explain that because rsync is running as part of Cygwin the local drives are referenced as /cygdrive/d/directory/ etc. Is it possible that Scheduled Tasks is having difficulty interpreting those directories?

  • Can the batch script actually access the network resource? Not just as in: does it has rights, but does your script use a network mapping, and is it present? – LPChip Feb 7 '17 at 10:31
  • All resources are local, besides the remote server. The remote server is specified by IP address. So, "username@ipaddress:/remotedirectory/". – Del Feb 7 '17 at 10:34
  • I've added further details on as to how the remote server and the local directories are referenced. I don't think the issue is with the remote server but perhaps with how the local directories are referenced, as its using Cygwin. – Del Feb 7 '17 at 10:51
  • Or, perhaps, rsync isn't loading at all in Scheduled Tasks because it can't access the Cygwin system? – Del Feb 7 '17 at 10:52
  • It should work as standalone utility without "logging" to cygwin's subsystem. Are you using full paths ? Create a cmd file, put everything there and run this cmd file via scheduler – Alex Feb 7 '17 at 10:58
1

I realised, after much deliberation, that Task Scheduler was having difficulty running the rsync command. It crossed my mind that it might have something to do with accessing Cygwin.

While I had added the Cygwin applications to the %PATH% variable and I could run rsync on demand, Task Scheduler still needed to be told to run the script in bash.

Changing the task Action to run "bash -l -c "/cygdrive/driveletter/directory/file" has allowed Task Scheduler to run the task successfully.

Credit really should go here: http://www.davidjnice.com/cygwin_scheduled_tasks.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.