Xp_cmdshell

/* This code does not work as echo statement has multiple lines in it*/
SET NOCOUNT ON
DECLARE @cmd VARCHAR(8000)
SELECT @cmd = 'echo
CREATE VIEW dbo.View_1
AS
SELECT Id
FROM dbo.Table_Test
> C:\view.sql'
EXEC master..xp_cmdshell @cmd
I want the above code to work as it is.
/* This code works fine as the echo statement is in a single line*/
SET NOCOUNT ON
DECLARE @cmd VARCHAR(8000)
SELECT @cmd = 'echo CREATE VIEW dbo.View_1 AS SELECT Id FROM dbo.Table_Test > C:\Script\view.sql'
EXEC master..xp_cmdshell @cmd

Its not possible. Are you trying to generate the sql scripts to a file?
You can generate the sql's to a file.
Master..xp_cmdshell 'sqlcmd -S ServerName -i f:\dynamic.sql -E>>f:\output.sql'
Is this the same problem you posted earlier as well?
https://social.technet.microsoft.com/Forums/sqlserver/en-US/f9ddd369-f4e2-4622-afbd-607e38a2a6b1/create-sql-files?forum=transactsql
--Prashanth

Similar Messages

  • BCP is not working in when i am executing using xp_cmdshell

    Declare @cmd varchar(300)
    Set @cmd=
    'bcp "SELECT definition + char(13) + ''GO'' FROM test.sys.sql_modules s INNER JOIN test.sys.procedures p ON [s].[object_id] = [p].[object_id] 
     WHERE p.name LIKE ''create%''" queryout "V:\SQLBackups\SP_scripts.sql" -C -T -t -w'
     exec xp_cmdshell @cmd
    below is the result i am getting its not creating any sql script its working perfectly from cmd prompt
    usage: bcp {dbtable | query} {in | out | queryout | format} datafile
      [-m maxerrors]            [-f formatfile]          [-e errfile]
      [-F firstrow]             [-L lastrow]             [-b batchsize]
      [-n native type]          [-c character type]      [-w wide character type]
      [-N keep non-text native] [-V file format version] [-q quoted identifier]
      [-C code page specifier]  [-t field terminator]    [-r row terminator]
      [-i inputfile]            [-o outfile]             [-a packetsize]
      [-S server name]          [-U username]            [-P password]
      [-T trusted connection]   [-v version]             [-R regional enable]
      [-k keep null values]     [-E keep identity values]
      [-h "load hints"]         [-x generate xml format file]
      [-d database name]        [-K application intent]
    NULL
    any help is highly appreciated 
    Thanks
    AK

    issue got resolved sql command should be in single line :)

  • NOT using xp_cmdshell, Can we check free space of drives in windows servers?

    Hello all,
    I have a strange situation here(may not be to you), as per client security standards,
    I should NOT use xp_cmdshell. Adding to this, I was asked to generate a report daily about drives and their free spaces.
    Having with xp_cmshell, we have numerous ways to execute this task easily but
    NO xp_cmshell. Also, I can't use xp_fixeddrives system proc because it doesn't show-up mounted drives.
    So, it would be great if you can share any other possible options using SQLCMD, PowerShell, T-SQL scripts etc that we can get the drives list (including mount points, root directory(C$), Quorum drive, MSDTC drives) and their free spaces.
    I tried a couple of ways like using  sys.dm_os_volume_stats() function which comes in SS2012. But, couldn't help.
    Appreciate your help and time in regarding.
    Thank you all!!

    Is powershell an option for you?
    If yes, its quite easy to come with PS script for this
    see examples here
    http://www.codeproject.com/Articles/757946/Retrieve-Disk-Space-of-Remote-Computers-using-Powe
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/08/use-powershell-to-create-a-report-displaying-free-disk-space.aspx
    As far as I know sys.dm_os_volume_stats  only gives the details ofabase files exist
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Executing an SSIS package from TSQL without using xp_cmdshell?

    How can I execute an SSIS package from TSQL without using xp_cmdshell?
    I have a web-app which calls some SQL which executes my SSIS package (a DTSX file, but stored in the server). But the security policy for my application won't permit me use to xp_cmdshell.
    I want to do this:-
    DECLARE @returncode int
    EXEC @returncode = xp_cmdshell 'dtexec /sq pkgOne"'
    Is there another way for executing a Package without going to the command line (e.g. is there some other system stored proc)?
    Thanks

    Whoa - don't go taking my words as saying "it should work".  I never said that - I just said I know less than you :)  I'm assuming that since the CLR is .Net, and you can launch a package from .Net code, you may be able to do so from the CLR. 
    But... I also know that CLR has lots of restrictions on it, and some of those may cause you to be unable to run it from the CLR.
    One thing I will say - I've never heard of anyone doing this.  That's got to tell you something about:
    Whether it can be done at all... although I think I'd have heard/seen something about how it's not possible.
    Whether it's a good idea... maybe other routes are less trouble.
    Talk to me now on

  • Problems enabling xp_cmdshell

    We migrated a SQL Server 2005 server to SQL 2008R2 SP3 this past Sunday, with one named instance. One of the things we missed was that xp_cmdshell was enabled on the old server. The SQL server name is fl2000-sql002 and the SProc is using this code:
    SET @bcpCommand
    = 'bcp.exe AdjustmentRequests.##AdjustmentRequestCSVFinal out "\\fl2000-netcon01\DefPath\Charge Imports\result.csv" -S fl2000-sql002 -U AdjustmentRequests -P [Pwd] -t, -c'
    EXEC
    master..xp_cmdshell
    @bcpCommand
    The programmers request was to grant the local SQL ID named 'AdjustmentRequests' the ability to execute xp_cmdshell, but I want to use a generic SQLProxy account in case future SProc's also need the
    ability. Because it is referencing a remote UNC path, I created a new dedicated domain proxy account named SQL002DB.Proxy.
    I've done this before years ago but I didn't document the exact steps, so I was searching for the process again. I tried a few different links, and then ended up on the link I recognized from the last setup on one of our other SQL servers...
    http://sqlblog.com/blogs/tibor_karaszi/archive/2007/08/23/xp-cmdshell-and-permissions.aspx.
    At this point in time, the instance doesn't not have a login for the SQLProxy account, nor the domain\SQL002db.Proxy account, there are not any entries in the Credentials, and there are not any entries in the SQL Agent\Proxies\OperatingSystem(CmdExec)
    containers. I refreshed all containers to confirm.
    The commands I'm attempting to use are below.
    --1, allow   xp_cmdshell
    EXEC sp_configure 'xp_cmdshell', 1
    RECONFIGURE
    GO
    --2, grant permission to xp_cmdshell
    USE master
    CREATE LOGIN SQLProxy WITH PASSWORD =   'XP_Cmdshell'
    CREATE USER SQLProxy FROM LOGIN SQLProxy
    GRANT EXECUTE ON xp_cmdshell TO SQLProxy
    EXECUTE AS login = 'SQLProxy'
    EXEC sp_xp_cmdshell_proxy_account   'Domain\SQL002DB.Proxy','Pwd'
    EXECUTE AS login = 'SQLProxy'
    EXEC xp_cmdshell 'DIR C:\*.*'
    REVERT
    Regardless if I login as sa or login with my domain account which is a member of the sysadmin role, I receive these messages upon execution:
    Configuration option 'xp_cmdshell' changed from 1 to 1. Run the RECONFIGURE statement to install.
    Msg 15023, Level 16, State 1, Line 4
    User, group, or role 'SQLProxy' already exists in the current database.
    Msg 229, Level 14, State 5, Procedure sp_xp_cmdshell_proxy_account, Line 1
    The EXECUTE permission was denied on the object 'sp_xp_cmdshell_proxy_account', database 'mssqlsystemresource', schema 'sys'.
    Msg 229, Level 14, State 5, Procedure xp_cmdshell, Line 1
    The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.
    Now I see the SQLProxy login ID listed, but nothing else. What am I doing wrong? The staff are sharpening their pitchforks because they are having to run this process manually.

    Logged in as sa:
    EXEC
    sp_xp_cmdshell_proxy_account[Domain\SQL002DB.Proxy],
    'Pwd'
    Msg 15137, Level 16, State 1, Procedure sp_xp_cmdshell_proxy_account, Line 1
    An error occurred during the execution of sp_xp_cmdshell_proxy_account. Possible reasons: the provided account was invalid or the '##xp_cmdshell_proxy_account##' credential could not be created. Error code: '5'.
    USE
    master;
    GO
    CREATE
    USER [Domain\SQL002DB.Proxy]
    FOR
    LOGIN [Domain\SQL002DB.Proxy];
    GRANT
    EXECUTE
    ON
    xp_cmdshell
    TO [Domain\SQL002DB.Proxy];
    Msg 15023, Level 16, State 1, Line 1
    User, group, or role 'Domain\SQL002DB.Proxy' already exists in the current database.

  • Xp_cmdshell error, but not calling xp_cmdshell anywhere

    I'm using SQL Server 2005.  My company uses a very large, complex legal services developed by an outside firm, with whom we work pretty closely.  I'm adapting a stored procedure that writes one record into a table which has several required columns
    (NOT NULL)  The procedure also invokes another stored procedure and a user-defined function.
    So far as I can tell, I'm passing in all of the required parameters; for any column that is not required, I'm passing in NULL.  I'm invoking the procedure as follows:
    EXEC sp_WriteARecord <key value 1>, <key value 2>, <key value 3>, <key value 4>, NULL, NULL, NULL, NULL
    When I make this call, I get the following error:
    Msg 229, Level 14, State 5, Procedure xp_cmdshell, Line 1
    The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.
    The problem is, there is no call to xp_cmdshell in any of the procedures or the function.  I don't think I've ever seen this before, unless I was, for some reason, trying to see if I could actually call xp_cmdshell.  I'm not a DBA, and I know that
    I have server-level Admin privileges, but I don't believe that's the problem.
    I hope this is enough detail to adequately describe the problem.  I'd be very grateful if anyone can point me in the right direction.

    The query that Sean gave you have a potential problem, the string xp_cmdshell may be split up over two lines in sys.comments. This is safer:
    SELECT object_name(object_id) FROM sys.sql_modules WHERE definition LIKE '%xp_cmdshell%'
    And you should have db_owner rights when you run this.
    Note: if procedures have been created WITH ENCRYPTION, you will come back empty-handed.
    But something is certainly calling xp_cmdshell. That we can tell from here.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • SQL Server 2012 - xp_cmdshell - second call fails.

    I have just upgraded a system from 2008 R2 to 2012 SP1.
    I have an issue with a scheduled SP that fails 'randomly' whilst processing/emailing a series of files created by a previous SP.
    The SP gets a directory list and processes each file. The processing involves issuing a 'move' command via XP_cmdshell and then adds the filename to a variable.
    At the end of the SP, the list of files is used as an attahement list to a mail command.
    The problem is that the first move works, then when the next file is moved I get a failure reported (SOMETIMES).
    The actual failure is: Incorrect syntax near 'Begi'. [SQLSTATE 42000] (Error 102). 
    I thought I had fixed it by inserting some 'debugging' select statements - but the problem came back.
    The call to xp_cmdshell is of the form 'move "filename and directory 1" "filenname and directory 2". After investigation it appears that more than one set of double quotes *may* have some bearing on the issue and I can resolve it by removing
    all the double quotes (no imbedded spaces in filenames so I am OK).
    Before I remove the quotes however, I would be interested if anyone can shed any light on the 'randomness' of the issue - it doesn't always occur and the adding of simple "Select 'AT Step x' " type debugging statements (with output to file and
    log output turned on in SQL Server agent job) appears to sometimes fix the issue.
    Stan

    Good news - I have got the code to post (I have stripped out some company specific parts).
    Bad news - the issue is not repeatable!
    I post the code however for you listening and viewing pleasure :-(
    alter PROCEDURE [dbo].[Test_TTF]
    As
    Begin
    SET NOCOUNT ON
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ARITHABORT ON
    SET ANSI_NULLS ON
    SET ANSI_NULL_DFLT_ON ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    SET QUOTED_IDENTIFIER ON
    Declare
    @ResultCode int,
    @ErrorCode int,
    @ErrorMessage varchar(2000),
    @f_id int,
    @m_id int,
    @gf_id int,
    @FileMask varchar(100),
    @TodayDate datetime,
    @DirectoryCmd varchar(600),
    @FileMoveCmd varchar(600),
    @FileName varchar(100),
    @FileProcessedDirectory varchar(500),
    @FileUnprocessedDirectory varchar(500),
    @FileAttachments varchar(max)
    Set @FileAttachments = ''
    Set @TodayDate = GetDate()
    Set @FileMask = '100???TC????.TXT'
    Set @FileProcessedDirectory = 'C:\Stan\T2\'
    Set @FileUnProcessedDirectory = 'C:\Stan\T1\'
    --Process files.
    --Get a list of files.
    Set @DirectoryCmd = 'Dir /b "' + @FileUnprocessedDirectory + @FileMask
    --Create FileList table variable.
    Declare @FileList Table (
    [f_id] [int] Identity(1,1) Not Null,
    [FileName] [varchar](100) Null
    --Get a directory list of the files.
    Insert Into @FileList
    Execute master.sys.xp_cmdshell @DirectoryCmd
    --Read the first file to process.
    Select Top 1
    @f_id = [f_id],
    @FileName = [FileName]
    From @FileList
    Where [FileName] Is Not Null
    And [FileName] <> 'File Not Found'
    order by [f_id]
    --Start of files loop.
    While (@@Rowcount <> 0)
    Begin
    -- select 'Starting to process ' + ltrim(rtrim(@FileName))
    --Build the file attachement list command.
    If Len(RTrim(LTrim(@FileAttachments))) = 0
    Set @FileAttachments = @FileProcessedDirectory + @FileName
    Else
    Set @FileAttachments = @FileAttachments + ';' + @FileProcessedDirectory + @FileName
    -- select 'Current Attachments = ' + ltrim(rtrim(@fileattachments))
    --Move the files to the processed directory.
    Begin Try
    Set @FileMoveCmd = 'Move "' + @FileUnprocessedDirectory + @FileName + '" "' + @FileProcessedDirectory + @FileName + '"'
    -- select 'Movecmd=' + @FileMoveCmd
    Execute @ResultCode = master.sys.xp_cmdshell @FileMoveCmd , NO_OUTPUT
    -- select 'File ' + @FileName + ' has been moved'
    End Try
    Begin Catch
    Set @ErrorCode = Error_Number()
    Set @ErrorMessage = Error_Message()
    Goto DumpErrorDetail
    End Catch
    --Read the next file to process.
    ReadNextFile:
    Select Top 1
    @f_id = [f_id],
    @FileName = [FileName]
    From @FileList
    Where [f_id] > @f_id
    And [FileName] Is Not Null
    And [FileName] <> 'File Not Found'
    order by [f_id]
    End --End of files loop.
    If @ErrorCode <> 0
    Return (@ErrorCode)
    Else
    Return(0)
    DumpErrorDetail:
    Begin
    Return(-1)
    End
    End --End of stored procedure.

  • EXEC master..xp_cmdshell

    Hi:
    I have a SSIS package, which, when I execute from Visual Studio it executes fine.
    It has about 10 Variables declared, all the 10 variables contain Oracle queries that are set to the Data SOurce in the Data Flow Task.
    When I run this package from Visual Studio the package runs fine but when I execute the same package from an SP
    Like this...
    EXEC master..xp_cmdshell 'dtexec /F "C:\XXX\Integration Services Project1\Integration Services Project1\XXXUsers.dtsx"'
    (harcoded the variables for now)
    It throws up errors for all the variables declared.. errors are as follows
    Error: 2014-08-21 16:47:55.39
       Code: 0xC02020F6
       Source: PERSON LIST XXX PersonList Data Source [2]
       Description: Column "ACTIVE_CARD_NO" cannot convert between unicode and non-unicode string data types.
    End Error
    Warning: 2014-08-21 16:47:55.40
       Code: 0x800470C8
       Source: PERSON LIST XXXX PersonList Data Source [2]
       Description: The external columns for XXX PersonList Data Source are out of synchronization with the data source columns.
    The external column "ACTIVE_CARD_NO" needs to be updated.
    End Warning
    Error: 2014-08-21 16:47:55.40
       Code: 0xC004706B
       Source: PERSON LIST SSIS.Pipeline
       Description: XXXX PersonList Data Source" failed validation and returned validation status "VS_ISBROKEN".
    End Error
    The string data from the source is coming as 'Unicode String', I have added a 'Data Conversion' task to convert it to string[DT_STR].
    What could be wrong here

    Hi Sudhakar,
    This issue is more related to SQL Server Integration Services, I will move this thread to SSIS fourm for better support.
    If you have any feedback on our support, please click
    here.
    Best Regards,
    Elvis Long
    Elvis Long
    TechNet Community Support

  • Xp_cmdshell to Copy Document based on ID

    Hi all,
    Is it possible to use xp_cmdshell to copy a document on the server to a shared folder using the code for the document.
    My example is - 
    A sql table with Code and FileLocation. 
    I know the codes for the documents but not where they are saved.
    Can i use xp_cmdshell to set the code which will then correspond to the right document and then copy that to a share I set in the sql command?
    Thanks

    Yes, it is possible. It's simple cmd shell scripting..
    A sql table with Code and FileLocation. I know the codes for the documents but not where they are saved.
    sounds like a contradiction. When you have a table where the file location is stored, then you "know" where they are saved. Otherwise the process behind is errorneous.
    E.g.
    DECLARE @Sample TABLE
    Code INT ,
    FileLocation NVARCHAR(MAX)
    INSERT INTO @Sample
    ( Code, FileLocation )
    VALUES ( 0, N'C:\Temp\myfile.txt' );
    DECLARE @cmd_statement NVARCHAR(MAX)= N'XCopy "%SOURCEFILE%" "%DESTINATIONPATH%" /I /Q /R /V /Y';
    SET @cmd_statement = REPLACE(@cmd_statement, '%DESTINATIONPATH%', '\\server\share');
    SELECT @cmd_statement = REPLACE(@cmd_statement, '%SOURCEFILE%', S.FileLocation)
    FROM @Sample S
    WHERE S.Code = 0;
    EXECUTE master.sys.xp_cmdshell @cmd_statement;
    But I would prefer a
    SQL CLR stored procedure. Cause it gives you better, fine grained control and error handling.

  • SP with xp_cmdshell gives an error in the MessageQueue, but executes successfully in SSMS.

    Hi All,
    I have a SP, which calls xp_cmdshell in it. This SP is being used in a MessageQueue. 
    The SQL server and Agent services are configured using a Domain service account, and this service account has a login under the sysadmin server role as well.
    When the MessageQueue is invoked, the SP returns the following exception :
    The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.
    But when I execute the SP in SSSMS, under the service account login (which is a sysadmin), it successfully executes.
    I even created the ##xp_cmdshell_proxy_account## credential, but the Message Queue never stops giving this error.
    This is how the queue looks like :
    CREATE QUEUE [dbo].[TestxmCmdshellQueue]
    WITH STATUS = ON ,
    RETENTION = OFF ,
    ACTIVATION (      STATUS = ON ,
                            PROCEDURE_NAME = [dbo].[SpWithxp_cmdshell_Init] ,
                            MAX_QUEUE_READERS = 5 ,
                            EXECUTE AS N'dbo'  ),
    POISON_MESSAGE_HANDLING (STATUS = OFF) 
    The Service account is configured as a Local Administrator in the Local Server as well.
    I am running SQL Server 2008 R2 Sp2 on a Windows Server 2008 R2 Enterprise Machine. 
    Please let me know what I am missing here.

    I Made TRUSTWORTHY = ON in the database and the SP executed without any problem by the Message Queue.
    No, that is not the solution.
    Yes, it works. And it is a lot simpler than the solution I pointed you to. But it opens a big security hole. Or, well, depending how things you are on your server, it may be entirely uncontroversial. But as long as I don't know anything, I will have
    to assume that it is a security hole. And even if there is no one today on the server who is db_owner in the database but who should not be sysadmin, that could happen in the future.
    So, to anyone else who is reading this: don't set your databases to be trustworthy, unless you fully understand the implication. The correction solution is to use certificate signing. I describe this in detail in my article, and this article also explains
    the dangers with TRUSTWORTHY.
    http://www.sommarskog.se/grantperm.html
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Xp_cmdshell proxy account

    hello,
    i have a weird case that i have two accounts on a database server, lets say AD and AL. the AD is a domain account and the AL is a local account. both of them are local administrators on that database server and both of them is a sysadmin on the sql
    server. i've enabled the xp_cmdshell, and i've created the ##xp_cmdshell_proxy_account##. now, in the ##xp_cmdshell_proxy_account## credential properties if i use the AD in the Identity field, the stored procedure that uses the xp_cmdshell works
    fine, but if i use the AL account i got the following error:
    "An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1385'."
    i've searched the error and i found something in http://msdn.microsoft.com/en-us/library/ms681385.aspx that the error code 1385 means (but i'm not sure
    if those codes are related to the error i'm getting):
    "Logon failure: the user has not been granted the requested logon type at this computer."
    i've tried to login with the AL account to the sql server and run for example "exec xp_cmdshell 'echo 123'" and it worked fine!.
    can anybody explain this or at least shed some light on the places that i didn't configure for the AL user ? 

    Please Check if the AL user has these rights
    Log on as a service (SeServiceLogonRight)
    Act as part of the operating system (SeTcbPrivilege) (only on Windows 2000)
    Log on as a batch job (SeBatchLogonRight) 
    Replace a process-level token (SeAssignPrimaryTokenPrivilege)
    Bypass traverse checking (SeChangeNotifyPrivilege)
    Adjust memory quotas for a process (SeIncreaseQuotaPrivilege)
    Specially
    Log on as a service (SeServiceLogonRight)
    Surender Singh Bhadauria

  • Xp_cmdshell giving error

    HI All,
    I was trying to get the list of all the files in the folder,am getting an error saying "
    '\\file01\EDW\Perf\' is not recognized as an internal or external command,
    Please help
    declare @files table (ID int IDENTITY, FileName varchar(200))
    insert into @files execute xp_cmdshell '\\file01\EDW\Perf\'
    select * from @files
    Thanks in Advance.

    xp_cmdshell doesnt list files in folder by itself
    i think what you need is this
    declare @files table (ID int IDENTITY, FileName varchar(200))
    insert into @files execute xp_cmdshell 'DIR "\\file01\EDW\Perf"'
    select * from @files
    where FileName NOT LIKE '%<DIR>%'
    AND FileName NOT LIKE '%bytes%'
    AND FileName IS NOT NULL
    courtesy
    http://oakdome.com/programming/SQL_FileListing.php
    Also account executing xp_cmdshell should be a sysadmin
    Otherwise you need to configure a proxy account for this
    http://www.databasejournal.com/features/mssql/xpcmdshell-for-non-system-admin-individuals.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Xp_cmdshell error

    Hi,
    I have an old SQL 2000 server that uses
    xp_cmdshell. Been working fine for years.
    Now it comes up with an error
    when I run this:
    exec master.dbo.xp_cmdshell 'dtsrun -E -Swsisql3 -NImport_APDIST'
    I get this error:
    Cannot load the DLL ppspps, or one of the DLLs it
    references. Reason: 126(The specified module could not be found.).
    So in
    troubleshooting I run this:
    use master
    go
    sp_helpextendedproc 'xp_cmdshell'
    the results:
    name dll
    xp_cmdshell
    ppspps
    I can't seem to figure out why the DLL is missing? I searched for
    ppspps.dll and is not on the server. Is this even the correct file?
    qeqw

    8Looks something is not what it should be on that server. When I run
    EXEC sp_helpextendedproc 'xp_cmdshell'
    on SQL 2000, I get:
    name            dll    
    xp_cmdshell     xplog70.dll
    DBCC CHECKDB and DBCC CHECKCATALOG on master could be a start to see whether there is plain corruption.
    But I would also look around to see if there are other spooky things.
    I guess that you can repair it by dropping and readding xp_cmdshell, but it is not that it is supported - then again, nor is SQL 2000 these days...
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Problems with xp_cmdshell

    Hi!
    I am trying to use xp_cmdshell for the first time.
    When I run the following command in a cmd window on the server it works. (it just calls a third party tool that takes backups)
    "C:\BackupScripts\Backup.bat" "FULL" "SSDBSERV\L008" "MH" "SQL_UAT"
    "C:\BackupScripts\Backup.bat" "FULL" "SQL01" "MH" "SQL_UAT"
    Now im trying to execute it via sql using xp_cmdshell so im running:
    exec master.dbo.xp_cmdshell '"C:\BackupScripts\Backup.bat" "FULL" "SQL01" "MH" "SQLUAT"'
    but I get the error:
    The system cannot find the path specified.
    Does the xp_cmdshell command handle the quotations funny? Am I doing something wrong?
    Thanks,
    Zoe 

    Sorted it!
    Just had to double the quotation marks at the start and end
    exec master.dbo.xp_cmdshell '""C:\BackupScripts\Backup.bat" "FULL" "SQL01" "MH" "SQLUAT""'
    Thanks for all your help!
    Zoe

  • Sybase xp_cmdshell in Oracle

    Can some one help me to migrate following code form sybase IQ to Oracle10.2
    call xp_cmdshell('echo "some thing" > ./temp_file');

    In addition to the above post, check below:
    Answers to "Why are my jobs not running?"
    and Metalink notes below.
    Dynamic SQL and System Commands Using DBMS_PIPE - 14082.1
    Calling Operating System Commands from PL/SQL using External Procedures - 99136.1
    -Anantha

Maybe you are looking for