How to run a bash script with task scheduler (Windows 10 V1903)

1

i want to automatically sync the folder on my windows pc to my external harddrive connected to a raspberrypi. My script works and just uses rsync to copy 2 folders over.

I want to automate it via Task Scheduler but it doesn't work. I tried running it directly as a bash script from Task Scheduler and i tried another thing that came to my mind. I wrote a batch file which executes my bash script. It works when executing the batch file per hand but when i do it via Task Scheduler it doesnt work anymore and i cant figure out why since i dont have error messages or something.

I also wrote another batch file which creates a folder and executed it via Task Scheduler which worked fine. The Problem hast to be something with Task Scheduler and bash.

Any help would be much appreciated!

Bash script:

#!/bin/bash

rsync -rtv -e "ssh -i /home/fernien/id_rsa" /mnt/g/100D3300/ root@192.168.158.35://mnt/share/Bilder/Normal
rsync -rtv -e "ssh -i /home/fernien/id_rsa" /mnt/g/Bilder\ Editiert/ root@192.168.158.35://mnt/share/Bilder/Editiert

Batch file to run this script:

tried different varieties. With -c, without -c, with "./" and without.

@echo off
c:\scripts\
bash.exe -c "./sync.bash"

Niklas G.

Posted 2019-07-18T12:15:22.980

Reputation: 11

1Do you mean cd /d c:\scripts\ in the second line of your batch file? – FedonKadifeli – 2019-07-18T13:13:58.807

Answers

1

Thanks to @FedonKadifeli. The Problem was in my script: This did work when executed from hand, i don't know why but it did.

@echo off
c:\scripts\
bash.exe -c "./sync.bash"

But it should look like this. After correcting it, it worked fine for me. Shouldve spent more time with batch scripting.

@echo off
c:
cd \scripts\
bash.exe -c "./sync.bash"

Fernien

Posted 2019-07-18T12:15:22.980

Reputation: 11