LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2013, 05:37 AM   #1
dpminusa
LQ Newbie
 
Registered: Mar 2010
Location: USA
Distribution: Gentoo
Posts: 16

Rep: Reputation: 1
Question Cygwin Bash Script Initiated from WIN 7 Task Scheduler Fails


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:
Code:
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:
Code:
/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.
Code:
$ ./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.

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:
Code:
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
Code:
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.
 
Old 09-20-2013, 05:47 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
It has been a long time since I used Windows.. (Win98)

But during the overlap I was using cygwin ssh from Win to Linux ( I didn't like putty , don't remember why )
to get that working I had a .bat script setup the environment for cygwin and launch ssh

perhaps it is the environment that is missing when setup in the Task Scheduler

Like I said, been a long time, just throwing this out as 'an idea' that may be worth exploring.
 
Old 09-20-2013, 06:11 AM   #3
dpminusa
LQ Newbie
 
Registered: Mar 2010
Location: USA
Distribution: Gentoo
Posts: 16

Original Poster
Rep: Reputation: 1
Smile Adding Windows environment for WIN 7

Thank you for the reply.

I am not using ssh, I am just using a mapping from one PC to another. This works fine for Vista but not for Win 7. I have a Powershell wrapper version for testing and modifying the environment that the Scheduler sees as an alternative. When I interrogated the environment with set-location env: all seemed to be ok, but ... I will try to add my mapping directly in the powershell script to explore your idea. I had read that sometimes this is an issue. Especially if you request elevation in the job.

I will report back.
 
Old 09-20-2013, 08:38 AM   #4
dpminusa
LQ Newbie
 
Registered: Mar 2010
Location: USA
Distribution: Gentoo
Posts: 16

Original Poster
Rep: Reputation: 1
Smile Added Drive Mapping in Task Scheduler Powershell Script

I added a drive mapping with my Powershell wrapper. It did not provide a solution. I think the mapping command was correct.
The Task Scheduler Action is:

Code:
powershell -file "C:\Users\User\Folder\Script.ps1"
The related script snippet is:

Code:
Function Rsync_Backup
{

# Add reference to Network Share with Drive Mapping J:.
new-psdrive -name J -psprovider FileSystem -root \\Server01\Backup


$process = New-Object System.Diagnostics.Process
$startinfo = New-Object "System.Diagnostics.ProcessStartInfo"

    
# To supress the mintty window use it to execute the script then the -w hide is available.
$Script = "c:\cygwin\bin\mintty.exe"
$startinfo.FileName = $Script


$folder = "Testing"
$startinfo.Arguments = " -w hide /bin/bash -l -e ~${user}/rsync_Windows_Backup ${backuphost} ${folder}"

    
# Redirect Process Std Out and Std Error.
$startinfo.RedirectStandardError = $true
$startinfo.RedirectStandardOutput = $true
$startinfo.UseShellExecute = $false

    
$process.StartInfo = $startinfo
$process.Start() | Out-Null 
$process.WaitForExit()

    
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()

}

# MAIN
$user = [Environment]::UserName
$backuphost = "windows"

Rsync_Backup | out-null
Any more ideas I could try? I am down to my last few hair folicals.

Thanks.
 
Old 09-20-2013, 10:14 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by dpminusa View Post
To check the LAN connection I also did a
Code:
net use J: \\server\share
It connects fine and allows listing and writes, etc.
Did you do that before or after running the script? According to this message, net use might be needed to make the drive visible to cygwin. A followup message suggests telling cygwin to mount the share itself, bypassing the drive lettering system.
 
Old 09-21-2013, 09:51 AM   #6
dpminusa
LQ Newbie
 
Registered: Mar 2010
Location: USA
Distribution: Gentoo
Posts: 16

Original Poster
Rep: Reputation: 1
Smile Explicit net use in Cygwin Environment

Quote:
Originally Posted by ntubski View Post
Did you do that before or after running the script? According to this message, net use might be needed to make the drive visible to cygwin. A followup message suggests telling cygwin to mount the share itself, bypassing the drive lettering system.
Thank you for the suggestion. I will try this and see what I get.

I have been relying on the drive mapping made in windows to be present within the scope of the Task Scheduler and within the scope of Cygwin without explicitly creating them again.

I already tried adding a net use with a powershell script in the task scheduler as you saw .

My script does run correctly within Cygwin from the $ prompt, it is just from the Task Scheduler in Win 7 that it fails to find the share. That is why I added the net use in my powershell wrapper as an experiment.

I am obviously missing something a bit subtle here in Windows 7. My script DOES run fine from the task scheduler in Vista Bus. 32.

Thanks.
 
Old 09-21-2013, 10:40 PM   #7
dpminusa
LQ Newbie
 
Registered: Mar 2010
Location: USA
Distribution: Gentoo
Posts: 16

Original Poster
Rep: Reputation: 1
Thumbs up Solution FOUND!

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:

Code:
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!!
 
  


Reply

Tags
bash, rsync, scheduler, win7



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cygwin issue with bash script jdwilder Other *NIX 7 09-20-2013 05:53 AM
Running Cygwin bash script from Windows kint Programming 1 04-12-2012 03:14 PM
1st script attempt; cygwin; fails "bash: myscript : command not found" engineerd1 Linux - Newbie 8 11-08-2009 04:03 PM
How to run a BASH script in a Batch file (with Cygwin) FaeDine Programming 2 10-27-2007 04:47 PM
task scheduler? is there any? bruno buys Linux - General 1 11-17-2003 03:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration