Bash script fails from Windows 7 task scheduler

1

In order to use rsync I created a Bash script. It runs fine from the Cygwin 32-bit 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 "/home/user/rsync_Windows_Backup >> /home/user/Documents_cron.log 2>&1"

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

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

The rsync command within my rsync_Windows_Backup Bash script is:

/bin/time -f "\nElapse (hh:mm:ss.ss) %E" \ 
rsync.exe -ravuz --copy-links "$SRC" "$DEST" >> "$LOG" \ 
2 >> "$LOG"

I tested the script from the Cygwin command line. It runs as expected, i.e.

$ ./rsync_Windows_Backup - succeeds.  

However, 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 available and can be written to, too.

I should add some more details, 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 can remove the first error by changing the configuration to Windows 7 in the General Tab of the Task Scheduler properties. I cannot see why the mkdir fails to see the share J:.

To check the LAN connection I also did a net use J: \\server\share. It connects fine and allows listing and writes, etc.

When I run the same task scheduler job in Windows Vista it does work fine.

Is this some finer NTLM issue or other permission issue on Win 7? I am stumped at the moment.

dpminusa

Posted 2013-09-18T09:08:46.833

Reputation: 71

Thank you for reading and revising my post. Some of the capitalizations were for emphasis. I assume you changed them back for compatibility with the search engine keywords. I did not see how to isolate and highlight sections. What is the correct procedure for that. PS: I am visually impaired so typos are problematic for me. Is there a spell checker feature that I missed. – dpminusa – 2013-09-19T07:14:49.177

Answers

1

I now have this working in Win 7 from the task scheduler as I need. Thank you to @netubsi and @firerat 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!!

dpminusa

Posted 2013-09-18T09:08:46.833

Reputation: 71