Results 1 to 12 of 12
  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't run SQLFULL script from SQL agent

    I created a SQLFULL.CMD script for a full backup. The script runs fine when exectud from within windows. However, it fails when ran from a SQLagent or a query. I have enabled xp_cmdshell.

    In the query window:
    This works: execxp_cmdshell'ping localhost';
    This fails with "null": execxp_cmdshell'C:\Progra~1\Micros~1\MSSQL.1\MSSQL\Backup\sqlfull .cmd';

    I am not getting any info in the event log or the dsierror.log file to help troubleshoot.

    The baffling part is that I can run it withing Windows but not SQL. any ideas?

  2. #2
    Moderator mikeymac's Avatar
    Join Date
    Jun 2003
    Location
    Syracuse, NY
    Posts
    883
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Default

    I don't know anything about execxp_cmdshell, but is that a space in the file name of the CMD file that you are trying to run?

    SQLFULL .CMD???

  3. #3
    Member
    Join Date
    Apr 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    wow that looks strange. It should read:

    exec xp_cmdshell 'C:\Progra~1\Micros~1\MSSQL.1\MSSQL\Backup\sqlfull .cmd';

  4. #4
    Moderator mikeymac's Avatar
    Join Date
    Jun 2003
    Location
    Syracuse, NY
    Posts
    883
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Default

    \sqlfull .cmd';

    That is a space, right? In between the red and the blue? I can't imagine that would work, if it is.

  5. #5
    Member
    Join Date
    Apr 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I can assure there is no space in the actual query. I'm not sure why there is one when I paste here. If the path is wrong (I have deliberately mistyped it) then I get a path not found error.



    Quote Originally Posted by mikeymac View Post
    \sqlfull .cmd';

    That is a space, right? In between the red and the blue? I can't imagine that would work, if it is.

  6. #6
    Moderator mikeymac's Avatar
    Join Date
    Jun 2003
    Location
    Syracuse, NY
    Posts
    883
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Default

    Tell you what...how about you post the contents of sqlfull.cmd? Maybe there's a variable that isn't being defined, or something.

  7. #7
    Member
    Join Date
    Apr 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Remember, the script runs when exectued directly in Explorer, but not as a query in Studio.


    set tsm_dir=C:\Progra~1\Tivoli\TSM\TDPSql
    set sql_dir=C:\Progra~1\Micros~3\MSSQL.1\MSSQL\Backup


    date < NUL >> %sql_dir%\sqlsched.log
    time < NUL >> %sql_dir%\sqlsched.log


    %tsm_dir%\tdpsqlc backup * full /tsmnode=zzzzzzzzz /tsmp=xxxxxxxx /tsmoptfile=%tsm_dir%\dsm.opt /logfile=%sql_dir%\sqlfull.log >> %sql_dir%\sqlsched.log


    Quote Originally Posted by mikeymac View Post
    Tell you what...how about you post the contents of sqlfull.cmd? Maybe there's a variable that isn't being defined, or something.

  8. #8
    Moderator moon-buddy's Avatar
    Join Date
    Aug 2005
    Location
    Somewhere in the US
    Posts
    5,354
    Thanks
    2
    Thanked 148 Times in 145 Posts

    Default

    Quote Originally Posted by osi9400 View Post
    Remember, the script runs when exectued directly in Explorer, but not as a query in Studio.


    set tsm_dir=C:\Progra~1\Tivoli\TSM\TDPSql
    set sql_dir=C:\Progra~1\Micros~3\MSSQL.1\MSSQL\Backup


    date < NUL >> %sql_dir%\sqlsched.log
    time < NUL >> %sql_dir%\sqlsched.log


    %tsm_dir%\tdpsqlc backup * full /tsmnode=zzzzzzzzz /tsmp=xxxxxxxx /tsmoptfile=%tsm_dir%\dsm.opt /logfile=%sql_dir%\sqlfull.log >> %sql_dir%\sqlsched.log
    Try running the SQL backup script by not invoking the separate shell as called by your script.
    Ed

  9. #9
    Moderator mikeymac's Avatar
    Join Date
    Jun 2003
    Location
    Syracuse, NY
    Posts
    883
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Default

    Also, check out this article: http://support.microsoft.com/kb/q255749/

    Again, I know next to nothing about xp_cmdshell...but a Google search showed me a lot of forums with users having flaky little problems with it.

  10. #10
    Member
    Join Date
    Apr 2009
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm not a DBA. How do you run external scripts in a SQL Agent without xp_cmdshell?

    Quote Originally Posted by mikeymac View Post
    Also, check out this article: http://support.microsoft.com/kb/q255749/

    Again, I know next to nothing about xp_cmdshell...but a Google search showed me a lot of forums with users having flaky little problems with it.

  11. #11
    Moderator moon-buddy's Avatar
    Join Date
    Aug 2005
    Location
    Somewhere in the US
    Posts
    5,354
    Thanks
    2
    Thanked 148 Times in 145 Posts

    Default

    Quote Originally Posted by osi9400 View Post
    I'm not a DBA. How do you run external scripts in a SQL Agent without xp_cmdshell?
    Just open a DOS prompt and run the SQL script minus the XPcmd_shell...
    Ed

  12. #12
    Senior Member rore's Avatar
    Join Date
    Nov 2005
    Location
    Montreal, CA
    Posts
    636
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    Hi,
    How do you know that execxp_cmdshell'ping localhost' works? Any log?

    Try this:
    exec xp_cmdshell 'start /w C:\Progra~1\Micros~1\MSSQL.1\MSSQL\Backup\sqlfull. cmd';

    Rudy

    Edit: without the space after sqlfull.

Similar Threads

  1. Script to run LOG backup
    By osi9400 in forum Microsoft SQL Server
    Replies: 12
    Last Post: 04-20-2009, 10:33 AM
  2. How to run a single script across multiple instances and servers
    By jimlane in forum Administrative Client
    Replies: 15
    Last Post: 05-20-2008, 02:59 PM
  3. Replies: 4
    Last Post: 02-11-2008, 12:32 PM
  4. Run BASH Script with Schedule (Linux)
    By byu_tsm in forum Backup / Archive Discussion
    Replies: 2
    Last Post: 03-08-2006, 04:43 PM
  5. How to run Unix Script before/after TSM schedule
    By sasa in forum Backup / Archive Discussion
    Replies: 5
    Last Post: 08-18-2005, 09:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •