Jump to content

Bat file will not run in Windows Schedule Tasks


Recommended Posts

Guest Doo4fun
Posted

Batch file runs at cmd.exe but exits with 0x1 when attempting to run in

Schdueled tasks.

My intent is to delete all files with the .bak extention in Z:\ (this

is a network share that is mapped on the local server) then copy the

most recent .bak file to that directory

 

In Schedule tasks the Run = c:\WINDOWS\System32\cmd.exe /c

D:\Copy2Share\FileCopy.bat

 

@ECHO OFF

rem This script Deletes all *.bak files

rem then Copies most recent .bak file to directory

 

set localdir=O:\SQL-Backup\

set destdir=Z:\

 

del /s "%destdir%*.bak"

 

for /f "delims=" %%a in ('dir "%localdir%*.bak" /b /od') do set

"file=%%a"

copy "%localdir%%file%" "%destdir%" >nul

 

Your assistance is appreciated.

Doo4fun

 

 

--

Doo4fun

------------------------------------------------------------------------

Doo4fun's Profile: http://forums.techarena.in/member.php?userid=50918

View this thread: http://forums.techarena.in/showthread.php?t=980326

 

http://forums.techarena.in

  • Replies 3
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: Bat file will not run in Windows Schedule Tasks

 

 

"Doo4fun" <Doo4fun.3ag1fd@DoNotSpam.com> wrote in message

news:Doo4fun.3ag1fd@DoNotSpam.com...

>

> Batch file runs at cmd.exe but exits with 0x1 when attempting to run in

> Schdueled tasks.

> My intent is to delete all files with the .bak extention in Z:\ (this

> is a network share that is mapped on the local server) then copy the

> most recent .bak file to that directory

>

> In Schedule tasks the Run = c:\WINDOWS\System32\cmd.exe /c

> D:\Copy2Share\FileCopy.bat

>

> @ECHO OFF

> rem This script Deletes all *.bak files

> rem then Copies most recent .bak file to directory

>

> set localdir=O:\SQL-Backup\

> set destdir=Z:\

>

> del /s "%destdir%*.bak"

>

> for /f "delims=" %%a in ('dir "%localdir%*.bak" /b /od') do set

> "file=%%a"

> copy "%localdir%%file%" "%destdir%" >nul

>

> Your assistance is appreciated.

> Doo4fun

>

>

> --

> Doo4fun

 

Don't use fixed share drive letters in scheduled tasks - it won't

work properly. Use UNC coding instead.

Guest Pegasus \(MVP\)
Posted

Re: Bat file will not run in Windows Schedule Tasks

 

 

"Doo4fun" <Doo4fun.3ahnrd@DoNotSpam.com> wrote in message

news:Doo4fun.3ahnrd@DoNotSpam.com...

>

> That was it. Really appreciate your response.

>

> Thanks,

> Doo4fun

>

 

Thanks for the feedback.


×
×
  • Create New...