sql 2008

shanj
shanj used Ask the Experts™
on
hello out their!
   i need a sql agent-job to run the following script, this script runs excellent as a batch job,


for /f "delims=" %%x in ('dir /od /a-d /b \\tvwlitesp01\Litespeed\\OBI\*.bak') do set recent=%%x
del /q C:\Databasebackup\*.bak
Copy \\tvwlitesp01\Litespeed\\OBI\%recent% C:\Databasebackup\OBIbackup.bak

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
lcohanDatabase Analyst

Commented:
You can put that in a .cmd file and execute it from a SQL job as a Operating System(CmdEXEC)" type not T-sql or you could run the SQL below in a SQL job:



exec xp_cmdshell 'for /f "delims=" %%x in (''dir /od /a-d /b \\tvwlitesp01\Litespeed\\OBI\*.bak'') do set recent=%%x
del /q C:\Databasebackup\*.bak
Copy \\tvwlitesp01\Litespeed\\OBI\%recent% C:\Databasebackup\OBIbackup.bak'

Author

Commented:
Hello Icohan!
    i ran the job in Management studio and i get the following

output
%%x was unexpected at this time.
NULL

_____________________________
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
Hello Rocky!
   i followed your link + the following as advised

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
GO
---------------
i excute the job as follows  the file exists on the c drive and has the following name copy_db.bat

EXEC master..xp_CMDShell 'c:copy_db.bat'
result is
output
'c:copy_db.bat' is not recognized as an internal or external command,
operable program or batch file.
NULL
It should be "c:\copy_db.bat"

Thanks,

Author

Commented:
Did not solve it

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial