![]() |
We need to run the scripts frequently in order to maintain the system infrastructure’s cleanliness and security when using a UNIX-based system. These repetitious chores involve system backups, health monitoring, as well as other upkeep duties. Automation is the finest and quickest technique to accomplish the goal in this situation. UNIX has task schedulers built in to help with this problem. The task schedulers function as intelligent alarm clocks. The OS will initiate the predetermined task when the alarm sounds. At and cron are the two primary tools used to carry out scheduled operations. CronA common software tool for job scheduling is cron. Cron daemon (crond) and cron configuration are its two main parts. To decide when to execute which operation, crond checks the cron setup. Usually, these duties are carried out at predetermined periods in the background. To run the commands, it loops over each file in the /var/spool/cron, /etc/crontab, and /etc/cron.d directories. No of the work or the time frame, it provides excellent flexibility (hour, week, month, year, or whatsoever). crontabThe tool used to edit that schedule on the command line is called Crontab. A crontab file, a configuration file that specifies shell commands to run on a regular basis according to a predetermined schedule, controls it. Present-day Linux systems include it preinstalled. Execute the below command to check if it is present in your system or not: $ dpkg -l cron ![]()
Execute the following command to install crontab: $ sudo apt-get install cron -y ![]()
The information required to execute each and every cron job is included in the crontab file, which is a script. Run the command below to view a complete list of the cron jobs that are currently scheduled for the current user. $ crontab -l ![]()
Run the command to make changes to the crontab script. $ crontab -e ![]()
The crontab script’s lines each describe a task. $ <minute> <hour> <month_day> <month> <week_day> <command_to_run> To execute backup.sh every day at 9:00 p.m. (21:00 hrs): 00 21 * * * /path/to/script > /path/to/log/output.log ![]()
cron Special Characters:
atAnother task scheduling service that enables us to run tasks at a particular time, but just once, is at. This utility also comes pre-installed with most Linux distros. To check if it is present in your system run the below command in the terminal: $ which at ![]()
To install the at executing the below command: $ sudo apt install at -y ![]()
By specifying a time parameter, we may schedule jobs via the command line with ease. $ at now + 2 hour ![]()
Conclusion:To conclude, we looked at various “cron” and “at” scheduling strategies in the article. The repetitive job execution along the way demonstrated the ease of use and versatility of “cron” services. However, the “at” only can carry out a duty once. |
Reffered: https://www.geeksforgeeks.org
Linux Unix |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |