2 Replies Latest reply on Sep 24, 2012 3:58 AM by od74

    How to start a sheduled tasks with SQL ?

    Rookie

      Hello,

       

      On Landesk management 9, i try to start an existing sheduled task with SQL but on to not succes.

      I already success to add computer in the task but not to start the execution of this task, any idea ?

        • 1. Re: How to start a sheduled tasks with SQL ?
          jtrently Apprentice

          Gab Polo,

           

          Here is a Batch file I use to start tasks from SQL.  It reads the task number in from "Task.Que" which is simply a list of task numbers. Ignore the logging if it is confused.

           

          echo on

          echo Created New Log > C:\TaskService.log
          Time /t  >> C:\TaskService.log
          Date /T  >> C:\TaskService.log

          for /F %%A in (c:\Task.que) do call :SetStatus %%A

          exit /b 99


          :SetStatus

          timeout /t 4 > nul

          echo Starting Task %1 >> c:\TaskService.Log

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "update LD_TASK SET MAX_RETRIES = '0' WHERE (LD_TASK_IDN = %1)" >> c:\TaskService.Log

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "update LD_TASK SET TIMES_TRIED = '0' WHERE (LD_TASK_IDN = %1)" >> c:\TaskService.Log

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "update LD_TASK SET RESCHEDULE_TYPE = '2' WHERE (LD_TASK_IDN = %1)" >> c:\TaskService.Log

          :SetStart

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "update LD_TASK SET NEXT_START = getdate( ) WHERE (LD_TASK_IDN = %1)" >> c:\TaskService.Log

          timeout /t 4 > nul

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "update LD_TASK SET TASK_STATUS = '0' WHERE (LD_TASK_IDN = %1)" >> c:\TaskService.Log

          :BeginAgain

          timeout /t 10 > nul

          sqlcmd -S tcp:annmondb01 -d LANDesk -Q "SELECT task_status FROM ld_task WHERE (LD_TASK_IDN=%1)" | find /V "rows affected)" | find "1"

          if %errorlevel% == 0 goto BeginAgain

          echo Task %1 Completed >> c:\TaskService.Log

           

           

          Good luck

          • 2. Re: How to start a sheduled tasks with SQL ?
            Rookie

            OK, thanks a lot, it is working