El TecnoBaúl de Kiquenet

Kiquenet boring stories

Posts Tagged ‘scheduled’

Scheduled Tasks

Posted by kiquenet en 24 junio 2014

Task Scheduler – Automated Emails – Windows Service – SendEmail.exe

http://yoursandmyideas.wordpress.com/2012/01/07/task-scheduler-in-c-net/
http://www.codeproject.com/Articles/2407/A-New-Task-Scheduler-Class-Library-for-NET

http://www.makeuseof.com/tag/send-automated-emails-save-time-sendemail-windows-task-scheduler/
http://www.howtogeek.com/125045/how-to-easily-send-emails-from-the-windows-task-scheduler/

http://www.intstrings.com/ramivemula/articles/sending-automated-emails-asynchronously-using-a-c-windows-service-in-conjunction-with-database-email-records-part-ii/
http://ruchitech.blogspot.com.es/2012/06/sending-automated-emails-using-c.html
http://fairwaytech.com/2013/06/simple-scheduled-task-runner/

http://stackoverflow.com/questions/18858512/c-sharp-console-app-to-send-email-at-scheduled-times

Quartz Enterprise Scheduler.NET

http://quartznet.sourceforge.net/

Conversion Date – SqlServer
http://stackoverflow.com/questions/207190/sql-server-string-to-date-conversion

SqlServerCrontab (NContrab)

https://code.google.com/p/ncrontab/wiki/SqlServerCrontab

In Sql Server (Jobs)

USE msdb
GO

SELECT TOP 3
    sj.job_id                 AS JobId,
    sj.name                   AS JobName,
    run_date                  AS RunDate,
    run_time                  AS Runtime,
    run_duration              AS RunDuration,
    CAST(
        CONVERT(CHAR(8), run_date, 112) + ‘ ‘ +
        STUFF(STUFF(RIGHT(‘000000’ + CONVERT(VARCHAR(8), run_time), 6), 5, 0, ‘:’), 3, 0, ‘:’)
        AS DateTime)              AS StartedAt,                   
    (CONVERT (VARCHAR,
        (DATEADD(ss,
            (CASE LEN(run_duration)
                WHEN 1
                THEN run_duration
                WHEN 2
                THEN run_duration
                WHEN 3
                THEN (CAST(Left(right(run_duration,3),1) as int)*60)
                    + (right(run_duration,2))
                WHEN 4
                THEN (CAST(Left(right(run_duration,4),2) AS int)*60)
                    + (right(run_duration,2))
                WHEN 5
                THEN (CAST(Left(right(run_duration,5),1) AS int)*3600)
                    + (CAST(Left(right(run_duration,4),2) AS int)*60)
                    + right(run_duration,2)
                WHEN 6
                THEN (CAST(Left(right(run_duration,6),2) AS int)*3600)
                    + (CAST(Left(right(run_duration,4),2) AS int)*60)
                    + right(run_duration,2)
              END ),
            CAST(
                CONVERT(CHAR(8), run_date, 112) + ‘ ‘ +
                STUFF(STUFF(RIGHT(‘000000’ + CONVERT(VARCHAR(8), run_time), 6), 5, 0, ‘:’), 3, 0, ‘:’)
            AS DateTime)))
        ,120))                    AS CompletedAt 
    FROM   msdb.dbo.sysjobhistory sjh WITH (nolock)
        INNER JOIN msdb.dbo.sysjobs sj WITH (nolock)
               ON sjh.job_id = sj.job_id
WHERE  sjh.step_id = 0
ORDER  BY run_date DESC,
          run_time DESC

 

References:

http://beyondrelational.com/modules/2/blogs/88/Posts/19361/when-exactly-scheduled-jobs-started-and-completed-sql-server.aspx

Posted in .NET | Etiquetado: , , , , | Leave a Comment »

Automatización en envío de correo: Send Automated Emails using SendEmail and Windows Task Scheduler

Posted by kiquenet en 28 enero 2014

Se puede automatizar el envío de correos aplicando Tareas Programadas de Windows y el comando SendEmail.exe.

Para crear tareas programadas (tasks scheduler) se utiliza el comando schtasks.exe o Start->Programs->Accessories->System Tools->Task Scheduler

Con el comando SendEmail.exe podemos configurar el envío de correos:

Examples below.

  • -f xxxxx@gmail.com : This parameter is the email address that will be the “sender.”
  • -t rdube@yahoo.com : This is the recipient’s email address.
  • -u Monday Status Updates : This is the subject
  • -m Here’s the analytics data for this week! : This is the message body.
  • -a Analytics_Channel1.csv Analytics_Channel2.csv Analytics_Channel3.csv : These are the attachments.
  • -s smtp.gmail.com:587 : SMTP server and port
  • -xu xxxxx@gmail.com : SMTP authentication ID name
  • -xp A1ienz2A51 : SMTP authentication password
  • -o tls=yes : SMTP uses TLS (or SSL)

.

sendmail2   Send Automated Emails Using SendEmail & Windows Task Scheduler

sendmail3   Send Automated Emails Using SendEmail & Windows Task Scheduler

sendmail4   Send Automated Emails Using SendEmail & Windows Task Scheduler

Referencias:

http://www.makeuseof.com/tag/send-automated-emails-save-time-sendemail-windows-task-scheduler/
http://caspian.dotconf.net/menu/Software/SendEmail/

http://www.makeuseof.com/tag/how-to-automate-windows-programs-on-a-schedule/

Posted in Scripts, Trucos | Etiquetado: , , | Leave a Comment »

How to Create, Modify and Delete Scheduled Tasks from the Command Line

Posted by kiquenet en 10 septiembre 2012

 

Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.

While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:

  • Manipulate tasks in batch scripts.
  • Control and create tasks on networked machines without having to login to them.
  • Mass create/sync task across multiple machines.
  • Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.

As you can probably imagine, the SchTasks command has more options than we can cover in this article so we are going to focus on showing some examples of common task configurations and what the respective task looks like in the Task Scheduler.

Referencia: http://www.howtogeek.com/51236/how-to-create-modify-and-delete-scheduled-tasks-from-the-command-line/

Examples
Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:

SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00

Modify ‘My Task’ to run at 2 PM:

SchTasks /Change /TN “My Task” /ST 14:00

 

Create ‘My Task’ to run C:RunMe.bat on the first of every month:

SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:

SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

 

Delete the task named ‘My Task’:

SchTasks /Delete /TN “My Task”

Note: this will raise a warning which you will need to confirm.

Bulk Creation

Like any other command line tool, you can include multiple instructions in a batch file to accomplish bulk creation (or deletion).

For example, this script:

SchTasks /Create /SC DAILY /TN “Backup Data” /TR “C:Backup.bat” /ST 07:00
SchTasks /Create /SC WEEKLY /D MON /TN “Generate TPS Reports” /TR “C:GenerateTPS.bat” /ST 09:00
SchTasks /Create /SC MONTHLY /D 1 /TN “Sync Database” /TR “C:SyncDB.bat” /ST 05:00

Produces these tasks: Backup Data, Generate TPS Reports, Sync Database

 

The ability to do this is a quick way to roll out new tasks or change existing schedules to many machines at once. As a way to ensure the tasks are updated, you could include the appropriate SchTasks commands in a domain login script which will update user machines when they log in.

Microsoft Documentation on SchTasks Command

http://www.howtogeek.com/51236/how-to-create-modify-and-delete-scheduled-tasks-from-the-command-line/

Posted in Comandos, Scripts | Etiquetado: , , | Leave a Comment »