Why does a batch file execute by a scheduled task in Win2K3 not copy files?

Why is my batch file failing or how can I figure out why?

I have a batch file that copies files from a development machine to a production machine.  When I run the bat file manually while logged in as an administrator, the files are copied successfully.  However, when I execute the bat file through scheduled tasks, even though the job runs and completes, no files are copied.  The job is scheduled to run under an administator account, has administrator permissons for the job, and the mapping is using the same administrator permissions.

This is the bat file:

===================
cd c:\windows\system32
start /wait net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y
cd e:\inetpub\wwwroot\pyrlman09
e:
echo on
mcopy K:\*.* e:\inetpub\wwwroot\pyrlman09 /S/e/Y/v/c/d/i
EXIT
===================

When I open K, there are files.

When I log the results of the scheduled task, I get the following in the log file:

===============
C:\WINDOWS\system32\ScheduledTasks>cd c:\windows\system32
C:\WINDOWS\system32>start /wait net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y
C:\WINDOWS\system32>cd e:\inetpub\wwwroot\pyrlman09
C:\WINDOWS\system32>e:
E:\inetpub\wwwroot\pyrlman09>echo on
E:\inetpub\wwwroot\pyrlman09>xcopy K:\*.* e:\inetpub\wwwroot\pyrlman09 /S/e/Y/v/c/d/i
0 File(s) copied
E:\inetpub\wwwroot\pyrlman09>EXIT
========================

But when I run the bat file manually the desired file gets copied.  Please advise as this has been a bane for at least a couple of years.  Any other suggestions are appreciated.
audExpertAsked:
Who is Participating?
 
B HConnect With a Mentor Commented:
in your bat file you said mcopy, but in the log it says xcopy ...

the task - what account is it scheduled to run as, and does that account have permissions to where you want to map the K drive?
why not change this:
start /wait net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y
to this:
net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y

and reverse these two lines:
cd e:\inetpub\wwwroot\pyrlman09
e:
such that:
e:
cd e:\inetpub\wwwroot\pyrlman09
0
 
Glen KnightCommented:
Are you specifying a user for te scheduled task?
If so does it have access to the folders/files at both locations?

If not you need to because it's unlikely te service account will have access
0
 
QlemoDeveloperCommented:
The log is not showing the error output. You have not provided a password to the net use. Is it the same as for the admin account?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
audExpertAuthor Commented:
There is no error in the log.  The error is that the number of files copied is 0.  When I run the bat file manually, the number of files copied is 1.  Of course, I have to remove the file from the target each time I do this test.  

True, I did not provide a password in the net use command but even when I do, the results are the same.  This is the optional line that I use:

start /wait net use K: \\AU-WEBDEV-VM\pyrlman09 thepassword /user:au-webdev-vm\JobUser /persistent:yes

This user name is in the administrator groups of both the target and source machine.  Please note that this job is pulling data from K, the source to E, the local machine.

Thank you .
0
 
QlemoDeveloperCommented:
Bryon,
If we optimize the cd and drive change, we do a
cd /d e:\inetpub\wwwroot\pyrlman09
That does both changing the drive and the folder.
The swap you suggest doesn't make any difference.

However, I agree to take out the unnecessary start command. It's output or error messages are not logged into the scheduler log, because net use runs in an own window if called with start. And there is no reason why the start should be done in conjunction with /wait (without that, it would make sense).
0
 
audExpertAuthor Commented:
My mistake in posting the bat file code.  With respect to the xcopy comment, I have been using mcopy but tried xcopy to see if my effort to use mcopy was the problem.  I simply pasted the xcopy version but I have been using mcopy.
0
 
QlemoDeveloperCommented:
Sorry, audExpert, had overlooked that you did not provide ANY credentials, which is ok if the tasks runs with an appropriate account (which it does).
0
 
QlemoConnect With a Mentor DeveloperCommented:
I suggest you remove the start command, maybe even use special file redirection to do the logging, like:

net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y 2>&1 >c:\netuse.log

0
 
audExpertAuthor Commented:
I logged the results of the job by setting the properites of the job in task scheduler.  The run command value is:
C:\WINDOWS\system32\ScheduledTasks\PyrlMans.bat >> C:\windows\system32\scheduledtasks\pyrlmanlog2.txt

However, I am now trying Qlemo's and bryon's recommended changes to the bat file.
0
 
B HCommented:
please check what credentials the task is configured to run as

also, you might add this to the end of each line that does something, so we can see all the output:
>> c:\batchlog.txt

so:
cd c:\windows\system32
start /wait net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y >> c:\batchlog.txt
cd e:\inetpub\wwwroot\pyrlman09
e:
echo on
mcopy K:\*.* e:\inetpub\wwwroot\pyrlman09 /S/e/Y/v/c/d/i >> c:\batchlog.txt
EXIT

include the changes already mentioned, the above is just an example

0
 
audExpertAuthor Commented:
Success.  It appears that the problem was the word "start."  I changed the bat file to read:

net use K: \\AU-WEBDEV-VM\pyrlman09 /persistent:yes /Y 2>&1 >c:\windows\system32\scheduledtasks\netuse.log.  Then I tested the bat manually and it copied the file from source to target.
I then deleted the test file on target and retried the job using the scheduled job.  This time the job completed and copied the test file to the target machine.  The netuse.log read as follows:
"The command completed successfully."

All of your help is very very much appreciated!!!!!!!!!!!  Thank you.  I would kindly like to split the points between sir Qlemo and Byron.
0
 
audExpertAuthor Commented:
I read that I needed to have the wait command in the net use statement to insure that the batch file didn't proceed before continueing.  I hope that eliminating "start /wait" is ok.
0
 
B HCommented:
it will wait for the net use to either work, or fail... without the start command

feel free to split points however you wish, or ask more questions :)
0
 
QlemoDeveloperCommented:
Absolutely. Start is used to "spawn" a program in-parallel, without  waiting. With the /wait switch, you can wait on programs which do  usually start without halting the calling program, like notepad. It's  perfectly fine to omit start /wait from your job.
 
 Example for proper use of start /wait:
 
REM -- This starts notepad, and continues immediately notepad.exe echo notepad started, no wait echo. REM -- This one waits. start /wait notepad echo notepad startet, wait
The last echo will be shown only after closing the second notepad.
0
 
audExpertAuthor Commented:
Thank you for that clarification.  I've tested the job and the task will definitely not work with the start /wait or /wait entries.  The reason I added it was that the drive connections sometimes drop and the job seems to proceed before these connections are entirely restored.  To test the new edits, I dropped or disconnected the mapping for K and tried the job.  While the mappings are not showing in the explorer windows, the job still succeeded.  Thanks again for your help.
0
 
audExpertAuthor Commented:
Help much appreciated.  Also appreciated learning how to capture output to a logfile.
0
All Courses

From novice to tech pro — start learning today.