Discussion Locked

scheduled batch script fails

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi i have a batch script in my schedule task that fails when its suppose to run. I did some troubleshooting and it doesn't seem to like the the mapped network drive. what the scrip is doing is copying files to the network trough a mapped drive. i can run the batch file manually but when it runs on schedule it fails, saying 0 files copied.

any ideas how i can get it to recognize the nework mapped drive?
by the way i changed the network drive letter in the script to the local hard drive and it executed fine.

thanks,

jhj

6 replies

by sgt_shultz

just to make sure we covered basic stuff, you are running task with sufficient/administrator rights, yes? or did you change your password recently? to check:
Start/Control Panel/Scheduled Tasks/select batch file task/Task/run task as...with correct password.
give us copy of batch file to look at...

by jhayesit

i don't think there is anything wrong with the script because i run the script in the command line, it works fine. It's just that it doesn't like the mapped drive on the schedule task for some reason.

here it is though.

@echo on

date /t > d:\devsqllogs\log.txt
time /t >> d:\devsqllogs\log.txt

xcopy "i:\sql server data\mssql\backup\base\*.bak" k:\ /E /F /H /Y >> d:\devsqllogs\log.txt

date /t >> d:\devsqllogs\log.txt
time /t >> d:\devsqllogs\log.txt

xcopy "i:\sql server data\mssql\backup\safeguard\*.bak" k:\ /E /F /H /Y >> d:\devsqllogs\log.txt

echo Script Finished @ >> d:\devsqllogs\log.txt

echo &time /t >> d:\devsqllogs\log.txt

blat d:\devsqllogs\log.txt -t dbwarning@verilet.com -s devsqlbaks

thanks,

by cactus pete

If the script is running when you click on it then you know it works when a user is logged in. However, the drive is not mapped when no one is logged in, so scripting like this won't work. Also, if a machine process is kicking it off, it runs in that context, and the system account does not have authority to run over the network.

First, try UNC naming instead of drive letters. Then try to specify the context [logon credentials] for the service that launches the script.

by jhayesit

the command line doesnt accept unc by design,
2. when i log on to test it, i copy it to the command line and it works fine, but if i hit run now on scheduled tasks, even though i am logged on,it fails. so i kind of makes sense that,

"Then try to specify the context [logon credentials] for the service that launches the script. "

i'll give this a try.

thanks,

by it killer

create an additional drivemapper script to map the network drive.Called it drivemapper.cmd or whatever you like, and that command line to your backup script. it should work for you.
Good Luck.

@echo on

REM Check if machine is on network
If Exist i:\ goto onnet

REM Attempt to map drives if G:\ wasn't found
call "c:\program files\drivemapper.cmd"

REM Check if machine is on network again
If Exist i:\ goto onnet

REM If not on network, skip backup process
goto end

date /t > d:\devsqllogs\log.txt
time /t >> d:\devsqllogs\log.txt

xcopy "i:\sql server data\mssql\backup\base\*.bak" k:\ /E /F /H /Y >> d:\devsqllogs\log.txt

date /t >> d:\devsqllogs\log.txt
time /t >> d:\devsqllogs\log.txt

xcopy "i:\sql server data\mssql\backup\safeguard\*.bak" k:\ /E /F /H /Y >> d:\devsqllogs\log.txt

echo Script Finished @ >> d:\devsqllogs\log.txt

echo &time /t >> d:\devsqllogs\log.txt

This discussion is closed to new replies.