General discussion

Locked

scheduled batch script fails

By jhayesit ·
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

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by sgt_shultz In reply to scheduled batch script fa ...

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...

Collapse -

by jhayesit In reply to scheduled batch script fa ...

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,

Collapse -

by Cactus Pete In reply to scheduled batch script fa ...

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.

Collapse -

by jhayesit In reply to scheduled batch script fa ...

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,

Collapse -

by jhayesit In reply to scheduled batch script fa ...

got it,

i changed the mapped drive to UNC and it worked.

thanks though

Collapse -

by IT Killer In reply to scheduled batch script fa ...

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

Back to Windows Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums