What is Cron Job?

Cron is a command line utility to run small and quick commands on a scheduled basis. This is a handy, classic sysadmin tool for automating various tasks by combining it with othe tools. For example, some people combine rsync and cron to automatically create a daily or weekly backup at a certain time. Some people use it to analyze server logs and combine it with mail function to send an email if there is certain kind of error detected in the logs.

Cron Jobs. According to google cron stands for “a… | by Ranjan Bajracharya  | Medium

Understand a cron job syntax

It’s time to learn about cron job syntax on crontab.

  • crontab -a <filename>: create a new <filename> as crontab file.
  • crontab -e: edit our crontab file or create one if it doesn’t already exist.
  • crontab -l: show up our crontab file.
  • crontab -r: delete our crontab file.
  • crontab -v: show up the last time we have edited our crontab file.

Cron vs cron job vs crontab

You are likely to come across three terms that sound similar to each other: cron, cron job and crontab. Let me quickly tell you what are those:

cron: This is the actual program you install on your system and run as a daemon.

cron job: A job in Linux is a program that is up and running. Cron can handle multiple tasks and run them at their scheduled time. Each of these tasks are referred to as ‘cron jobs’.

crontab: This is the file (and command) where you define what task to run and how often to run it. A crontab can have multiple cron jobs in it in a tabular form where each row is a cron job.

Conclusion

On a Linux system, the cron job runs and completes our usual tasks (terminal commands). The bash command on the terminal, how to configure our task schedule, and making sure to capture all possible errors when our script is running in production are the most crucial aspects of learning about cron jobs.

Image: https://miro.medium.com/max/1400/1*pD_YMyWDg8A2grOrbaNS6g.jpeg

Leave a Comment

Your email address will not be published. Required fields are marked *