Crontab - Technological watch
Introduction
Crontab is a tool used to run commands or scripts on a schedule.
The use cases would be:
- Make backups every day
- Renew your SSL certificates
- Schedule long-running tasks like sending mass e-mails
- Clear the temporary files
- Check for updates
- Put some data in a cache
- Optimize SQL databases
- And a lot of other cases ! š
Installation
Usually, it is installed by default. But you can find the package:
Usage
To list all the jobs you have in your crontab profile, you can do:
To edit the jobs, you can do:
Syntax
The crontab syntax is simple and looks like this:
You can use caracter values like:
Examples
Here as some examples to better understand:
If you want to run a script every day at 1am (and 0 minutes), you can write:
If you want to run a script every 5 minutes:
Or you can do more specific tasks: At 22:00 on every day-of-week from Monday through Friday.
Configuration
You can deny or allow a user to modify his crontab.
To do this, create a file /etc/cron.allow or /etc/cron.deny.
- If /etc/cron.allow file exists, you need to be in this file to write crontab.
- If /etc/cron.deny file exists, you need to NOT be you can deny or allow a user to modify his crontab.
The best case is to create only one of these two files, and set the users you want into. in the file to be able to use write a crontab.
The best case is to create only one of these two files, and set the users you want into.
The root user bypass these verifications.
ā ļø The /etc/cron.allow and /etc/cron.deny files manage the access to the crontab command. If a user has a crontab, and after we remove it from the /etc/cron.allow file, the tasks will still be run !
More
If you want to test your crontabs, there is a nice website that you can find here: https://crontab.guru.
You can find cron alternatives in your favourite language like Nodejs (https://www.npmjs.com/package/cron), or in python (https://github.com/dbader/schedule)
Atomic design - Technological watch
Learn what is the atomic design in less than 5 minutesĀ !
Redis - Technological watch
Learn what is Redis in less than 5 minutesĀ !
Svelte - Technological watch
Learn what is Svelte in less than 5 minutesĀ !
Jenkins - Technological watch
Learn what is Jenkins in less than 5 minutesĀ !
PicoCSS - Technological watch
Learn what is PicoCSS in less than 5 minutesĀ !
OpenAPI / Swagger - Technological watch
Learn what is OpenAPI / Swagger in less than 5 minutesĀ !
HashiCorp Vault - Technological watch
Learn what is HashiCorp Vault in less than 5 minutesĀ !
RabbitMQ - Technological watch
Learn what is RabbitMQ in less than 5 minutesĀ !