Scheduled tasks, or cron jobs, are processes that run automatically in the background. Generally speaking, a cron job is a Linux utility that sets a command or a set of commands to execute at specific times or frequencies to perform specific tasks on any VPS (/vps).
Using cron jobs, you can automate specific tasks, such as sending automated emails, automatic backups, clearing your server\'s cache, deleting temporary files, and basically anything you can think of. Some practical examples of using cron jobs include receiving emails at 7 AM from a department store, receiving government payments, or your mobile phone alarm going off.
The use of cron jobs is not a theoretical novelty; it\'s a utility that has supported technological development for years and is important for understanding the algorithmic processes that occur automatically.
How to install Cron Jobs on Linux? To install this utility, you must run the following command on your Debian / Ubuntu machine:
The above command will install the utility, creating a file called crontab in the /etc/ directory (/etc/crontab)To edit crontab in Debian/Ubuntu, you can use your favorite editor; in our case, we\'ll use nano.How to edit Crontab in Linux?
nano /etc/crontabThis will open a file with example syntax like the following:
SHELL=/bin/sh PATH=/usr/local/sbin :/usr/local/bin:/sbin:/bin :/usr/sbin:/usr/bin 17 root cd / && run-parts --report /etc/cron.hourly 25 6 * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Basic crontab / cronjob syntax
The basic syntax structure for running crontab is as follows:minute hour day_of_month month day_of_week command_to_executeA basic example of using crontab to run a URL at 7 AM:
0 7 * curl https://mox.clIn this case, at 7 AM, it executes the CURL function to access the website in question (the asterisk represents any number or, in this example, any day). Another basic example, to reset the RAM of your Debian/Ubuntu virtual machine, could be:
0 free -m
Comments
0Be the first to comment