dpminusa
dpminusa

Reputation: 327

Windows 7 Task Scheduler BASH Script Fails

In order to use rsync I created a BASH script. It runs fine from the Cygwin shell in WIN 7 but fails when run from the WIN 7 Task Scheduler. My Task Scheduler Script is a simple:

c:\cygwin\bin\bash.exe -l -c "~user/rsync_Windows_Backup 2>&1 >> ~user/Documents_cron.log"

The initial directory is set to C:\Cygwin\bin.

My BASH script is a typical rsync command with [options] SRC DEST and some related housekeeping.

The rsync command within the "rsync_Windows_Backup" BASH script is:

/bin/time -f "\nElapse (hh:mm:ss.ss) %E" \ 
rsync.exe -v -rltz --chmod=a=rw,Da+x -u "$SRC" "$DEST" >> "$LOG" \ 
2 >> "$LOG"

$ ./rsync_Windows_Backup - succeeds.  

But the Task Scheduler Job fails carping that it cannot find the DEST Folder that the BASH script references. When I do a "cd DEST" from the BASH command line the Folder is avialable and can be written to.

I should add some more details that the sender is a WIN 7 desktop that is mapped to a Vista desktop receiver with a drive mapping J:. The BASH script does start but fails with:

rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
rsync: mkdir "/cygdrive/J/DocumentsBackup" failed: No such file or directory (2) rsync error:  error in file IO (code 11) 

I have tried several ideas to influence how WIN 7 handles mappings and permissions assuming this is the root of the problem. So far nothing seems to help.

Another characteristic is that the exact same BASH script and Task Scheduler Job does succeed it WIN Vista Business Edition. So I am assuming there is something in WIN 7 that I am missing.

I am stumped and could use some guidance.

Thanks.

Upvotes: 0

Views: 1926

Answers (3)

jcockrel
jcockrel

Reputation: 61

You can also just use the network address directly in cygwin:

DEST="//server/share/User/FolderBackup"

Cygwin mounts local and mapped drives under /cygdrive. Using taskscheduler in win7 if you list the contents of /cygdrive, all you will see are local drives???

Upvotes: 1

dpminusa
dpminusa

Reputation: 327

I now have this working in Win 7 from the task scheduler as I need. Thank you to @netubsi and @firerat of LinuxQuestionsorg and @konsolebox for the suggestions that lead to a solution.

Here is what I did:

cmd /c net use T: '\\server\share'        # Created a separate temporary share for Cygwin
DEST="/cygdrive/T/User/FolderBackup/"     # Use temporary Share in Destination
rsync -avuz --copy-links "$SRC" "$DEST"   # Do backup
cmd /c net use T: /delete                 # Remove temporary share 

It appears that in WIN 7 the share created in Windows is NOT available to a Cygwin script, IF it is launced from the Win 7 task scheduler. It IS available if the script is launced from the Cygwin command line. It also appears that this is NOT an issue in Win Vista.

This seems odd to me. Perhaps there is another explanation that I am missing. However I am just relieved to have this working!!

Upvotes: 2

konsolebox
konsolebox

Reputation: 75558

First option is to run your script as

c:\cygwin\bin\bash.exe -l -c "~/rsync_Windows_Backup >> ~/Documents_cron.log 2>&1"

If you want to capture the stderr output as well, you have to place it in front to copy the fd of the file, and not of stdout.

Make sure that rsync_Windows_Backup has executable permissions. Running ls -l ~/rsync_Windows_Backup should show it.

If it doesn't work, try to use absolute paths. On your Cygwin screen where the current direcory shows ~ in the prompt type pwd which would show something like

User@System ~
$ pwd
/home/User

Basing from that as an example your command should now be like:

c:\cygwin\bin\bash.exe -l -c "/home/User/rsync_Windows_Backup >> /home/User/Documents_cron.log 2>&1"

Upvotes: 0

Related Questions