Link to home
Start Free TrialLog in
Avatar of shanj
shanj

asked on

sql 2008

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
Avatar of lcohan
lcohan
Flag of Canada image

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'
Avatar of shanj
shanj

ASKER

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

output
%%x was unexpected at this time.
NULL

_____________________________
Avatar of shanj

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of rocky_lotus_newbie
rocky_lotus_newbie
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shanj

ASKER

Did not solve it