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

7,584

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"
Share:
7,584

Related videos on Youtube

Niklas G.
Author by

Niklas G.

Updated on September 18, 2022

Comments

  • Niklas G.
    Niklas G. almost 2 years

    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/ [email protected]://mnt/share/Bilder/Normal
    rsync -rtv -e "ssh -i /home/fernien/id_rsa" /mnt/g/Bilder\ Editiert/ [email protected]://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"
    
    • FedKad
      FedKad almost 5 years
      Do you mean `cd /d c:\scripts` in the second line of your batch file?