Thoener
Thoener

Reputation: 1

SQL Script (CronJob) with Mail

I have to write a script, that runs ones a day and checks in a SQL Server database for the birthday of customers. And if they have birthday the script will send a personal mail (name etc.) to this person.

my problems: The SQL-part is no problem, but I have no idea how to work with scripts/cronjobs whatever. Which language I should use and how to send mails with scripts.

Upvotes: 0

Views: 1877

Answers (1)

Andriy Ivaneyko
Andriy Ivaneyko

Reputation: 22051

Linux cron jobs setup

Take a look of how to work with cron jobs here

To send emails take a look at this article.

Basically your flow to resolve problem above would be next:

  • write bash script which talk to sql and send email if needed with one of command in article provided above.

  • schedule daily or hourly execution of that script in cronjobs.

That's all. Links above contain all requested by you information.

Windows "cron jobs" setup

The windows equivalent to a cron job is a scheduled task. There are use full instruction of how to schedule a task on official site ( i am sure that for Windows Servers steps would be quite the same).

So you need to create windows script witch would dial with sql and send email and than schedule script execution as task. See Guide to Windows Batch Scriptiong for details of how to write DOS-style batch files. Also take a look on How to send a simple email from a Windows batch file?, here you could find working suggestion of how to add code which sends email from windows script file.

Alternative

You could consider using Pycron which is a clone of the well-known cron job scheduler linux flavored operating systems, the implementation is platform-independant, so you could install it and use on Windows.

Upvotes: 1

Related Questions