SQL Agent Job Step using operating system (CmdExec)

  • Particulars

    SQL 2008 SP1 Enterprise

    Server 2008 Server Enterprise

    We moved to a new 3rd part backup tool to handle all SQL backups. I was tasked with configuration and assistance in setting up alerts and attempting to integrate SQL alerts with this 3rd party tool to execute on demand backups (for full logs specifically).

    The 3rd party tool can create a "script" which is basically a .bat file which logs into the backup tool's Comm Center and initiates the job.

    Simple enough...

    If you are on the SQL server, double click the .bat file...a DOS window opens, logs in, initiates a job which can be seen through the 3rd party tools interface and executes the backup job correctly.

    I tried to set up a SQL Agent job to execute the bat file and it fails with a login error...

    I opened up a DOS window and navigated to the location of the .bat file manually and executed the .bat file via command line and it works...so the process has to be re-directed to the home directory of the .bat file is what I was thinking

    Simple enough...

    Attempt two was me creating a job step that executed operating system (CmdExec) commands.

    I tried two different ways.

    1st

    I created a second .bat file that held the commands to navigate to the correct location

    CD\

    CD\c:\commvault_scripts

    DB_Log_Backup.bat (which is the .bat to run the actual log backup job)

    Everything worked like a charm

    2nd

    I decided to just put the code directly in the job command execution window and bypass creating a second .bat file

    CD\

    CD\c:\commvault_scripts

    DB_Log_Backup.bat (which is the .bat to run the actual log backup job)

    job runs to success but does NOT initiate the 3rd party job.

    I turned on logging on the job step

    1st attempt has the correct output

    C:\Windows\System32>cd \

    C:\>cd \commvault_scripts

    C:\CommVault_Scripts>DB_UTILS_Log_Backup.bat

    User logged in successfully.

    Started the job(6393)

    Job completed successfully.

    User logged out successfully.

    2nd attempt has the following and nothing more

    C:\Windows\System32

    I would REALLY like to figure out if I can actually use the code directly in the command window vs. creating a second .bat file for each database as that would be VERY time consuming.

    Can anyone please comment if they have done any type of DOS command prompt coding inside a job step?

    Thanks in advance,

    Lee

  • got it figured out...basically I didn't figure out how to work 'as is' with calling the bat file directly...

    What I did do is have to go into the .bat file and declare the full path to a directory and once I did that it actually worked.

    so a little recap...the .bat file looks to a second file (which I didn't mention in the previous post).

    The second file is actually an input file that holds information about the job that is going to be executed.

    Inside the .bat file I needed to define the full path to the input file and that allowed everything to work.

Viewing 2 posts - 1 through 1 (of 1 total)

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