using xp_cmdshell

  • How to search .BKP and .TRN files using xp_cmdshell (single Query)? Is it possble?

  • Please do explain a bit more what you're trying to do.

    xp_cmdshell can do what a DOS prompt can do. (it's why it's named as it is)

    Can you search those files yourself from a DOS prompt? (for whatever it is you want to search for?)

    To avoid misunderstandings, please also clarify what exactly your .BKP and .TRN files are.

    File extensions in windows aren't exactly set in stone.

    /Kenneth

  • Yes, it's possible...

    EXEC Master.dbo.xp_CmdShell "DIR d:\path\*.trn,d:\path\*.bkp /s/b"

    If you actually want to use the file names, create a table with a nice wide VARCHAR column and do this...

    INSERT INTO yourtable (widevarcharcolname)

    EXEC Master.dbo.xp_CmdShell "DIR d:\path\*.trn,d:\path\*.bkp /s/b"

    There are some undocumented xp calls that can be made , as well.  They're great because they don't require SA privs but they also stink because they didn't carry them forward in SQL Server 2005.

    Now that I mention that, I think xp_CmdShell was renamed in SQL Server 2005, as well?  Anybody know for sure?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Nope still exist albeit disabled by default.  And finally the account requirement is documented. 

    http://msdn2.microsoft.com/en-us/library/ms175046.aspx

    Kind regards,

    Gift Peddie

    Kind regards,
    Gift Peddie

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply