created - 07/2023         Edited - 06/2024

SQL Task Automation Made Easy: Cron Job vs. DBHawk Scheduler

Rina Nahar

Many Databases - Single Tool for Database Developers, DBAs, & DevOps

What is a cron job scheduler?

It is a specific task you schedule to run automatically on a Unix/Linux like system using cron. It's essentially a single line in a crontab file that tells the cron daemon (a background service) what to run and when.

Here's a breakdown of cron expression:

What it runs: Cron can execute any command or script that your system can understand. This could be things like:

  • System maintenance tasks (updates, backups)
  • Downloading files
  • Sending automated emails or reports
  • Website monitoring
  • Automating running SQL Queries at the desired repeat intervals and delivering results 

Understanding cron configuration: To set up a cron job, using a special syntax with five fields specifying:

       Cron expression is a string with following details:

  • Minute (0-59)
  • Hour (0-23)
  • Value for the day-of-month field (1-31)
  • Month (1-12)
  • Day-of-week  field(0-6, with 0 being Sunday)

You can use special characters like asterisks (*) as wildcards to represent any value within a field.

For instance, a job with * * * * * would run the command every minute, while 0 0 * * * would run it at midnight every day.

To create a job run At 04:05 on day-of-month 10 and on Monday, you can create a cron job like this:

 5                4       10        *           1

Minutes   hour  day    month    day

For various Cron syntax check out this site https://crontab.guru/

Why you should use cron to run repetitive tasks?

Benefits: Cron are a powerful tool for automating repetitive tasks, saving you time and ensuring tasks are completed consistently. They're especially useful for system administrators and developers who need to schedule regular maintenance or data processing. It is great way to schedule various automation jobs on Linux or unix system. 

Not every cron scheduler is made equal, but you can choose one that can provide an error log and a full audit for all job executions. That way, you can have more control over your batch scheduling process. Here are more features you can expect from an efficient solution:

An efficient and well-designed job scheduler automates the workflow on your preferred applications and platforms. It simplifies batch scheduling and allows you to see scheduled tasks while they run. Moreover, it provides up-to-date status information on all running jobs and lets you run repeated jobs every hour, day, or minute of the week, or you can restrict them during peak hours.

DBHawk Scheduler:

DBHawk scheduler is designed as a crontab to schedule repetitive SQL jobs. DBHawk Job supports scheduling various SQL jobs. Intuitive GUI screen makes it easy to schedule any complex scheduled jobs.

Users can choose the delivery results by email, file manager, s3 or directly to the sftp sites.

Output formats can be csv, text, html or pdf. With DBHawk job, user can use the default options with the drop down to configure variou intervals such as weekdays, day of the week, and scheduled time for job to run.

cron job scheduler - DBHawk

cron job scheduler - DBHawk

It also supports to retry jobs if scheduled job fails to run during specific time.  Please note that, behind the scene DBHawk uses the quartz library and cron automatic job syntax is little different than the cron job (Linux).

DBHawk requires a quartz cron expression which is different syntax than the cron job but very powerful.

e.g if you have a cron expression like this 0 0 0 ? * * *  -

seconds    Minutes    Hours    Day Of Month    Month    Day Of Week    Year

0                0                 0              ?                         *                            

If you need to create a complex cron schedule expression to run job at 10:15 last Friday of every month, You can use following expression:  0 15 10 ? * 6L 

DBHawk cron job expression

DBHawk cron job expression

As per above DBHawk scheduler cron expression screenshot, and based on the cron format expression, SQL job trigger will fire at 10:15 last Friday of every month.

For more information about understanding and generating quartz cron expression, please visit https://www.freeformatter.com/cron-expression-generator-quartz.html

DBHawk cron job scheduler also supports daylight saving time (DST).


Tags


You may also like

Many Databases, Single Tool, No Client Software

Get started for free.

Sign Up to see how DBHawk provides zero trust database access and development across all databases.


No Credit card required!