{"id":18211,"date":"2021-09-13T06:53:00","date_gmt":"2021-09-13T06:53:00","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=18211"},"modified":"2025-12-17T03:03:49","modified_gmt":"2025-12-17T03:03:49","slug":"cron-job","status":"publish","type":"post","link":"\/tutorials\/cron-job","title":{"rendered":"Cron job explained: Syntax, scheduling, and best use cases"},"content":{"rendered":"<p>A cron job is a time-based scheduler in Unix-like operating systems, such as Linux and macOS. It automates repetitive tasks like backups, system maintenance, and script execution.<\/p><p>Users define a schedule and command in a crontab file to keep critical processes running consistently in the background without manual intervention.<\/p><p>To use cron effectively, you need to understand its core components:<\/p><ul class=\"wp-block-list\">\n<li><strong>Syntax and operators<\/strong>. Cron uses five timing fields (minute, hour, day of month, month, and day of week) and special characters, such as asterisks and slashes, to define intervals.<\/li>\n\n\n\n<li><strong>Configuration<\/strong>. Users manage schedules with the <strong>crontab<\/strong> command or by placing scripts in specific system directories.<\/li>\n\n\n\n<li><strong>Permissions<\/strong>. The <strong>cron.allow<\/strong> and <strong>cron.deny<\/strong> files control access and help maintain system security.<\/li>\n\n\n\n<li><strong>Practical application<\/strong>. Common use cases include automating database backups, clearing server caches, and sending periodic email reports.<\/li>\n<\/ul><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-a-cron-job\">What is a cron job?<\/h2><p>A cron job is <strong>a utility that lets Linux and Unix users run commands or scripts automatically at a specified time and date<\/strong>. Instead of running a command manually every day or week, you schedule it once, and the system executes it in the background at the set time.<\/p><p>This automation is important for server management. For example, a system administrator managing a virtual private server (VPS) cannot back up databases manually every night at 3:00 AM.<\/p><p>A cron job handles this task reliably, improving efficiency and reducing human error.<\/p><p>Common cron job use cases include:<\/p><ul class=\"wp-block-list\">\n<li><strong>System maintenance<\/strong>. Deleting temporary files, rotating log files, or clearing cached data to free up disk space.<\/li>\n\n\n\n<li><strong>Data management<\/strong>. Dumping MySQL databases to a backup folder or syncing files between remote servers.<\/li>\n\n\n\n<li><strong>Notifications<\/strong>. Sending automated email digests, checking for system updates, or monitoring disk usage and alerting admins when space runs low.<\/li>\n\n\n\n<li><strong>Web applications<\/strong>. Triggering PHP scripts for tasks such as newsletter distribution or subscription renewals.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-does-a-cron-job-work\">How does a cron job work?<\/h2><p>A cron job <strong>runs through the cron daemon (crond)<\/strong>, a background service that runs continuously and executes commands defined in <strong>cron table (crontab)<\/strong> files.<\/p><p>Every minute, the daemon checks the configuration files and determines whether any tasks are scheduled to run at that time.<\/p><p>It&rsquo;s important to distinguish between the two types of configuration files:<\/p><ul class=\"wp-block-list\">\n<li><strong>System crontab<\/strong>. Located at <strong>\/etc\/crontab<\/strong>, this file handles system-wide tasks and only root users can edit it. It includes an extra field that specifies which user runs the command.<\/li>\n\n\n\n<li><strong>User crontab<\/strong>. Each user has their own crontab file. The storage location varies by distribution, such as <strong>\/var\/spool\/cron\/crontabs\/<\/strong> on Debian and Ubuntu and <strong>\/var\/spool\/cron\/<\/strong> on RHEL, CentOS, and Fedora. Users edit these files with the <strong>crontab -e<\/strong> command, and the tasks run with that user&rsquo;s permissions.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-understanding-crontab-syntax-and-operators\">Understanding crontab syntax and operators<\/h2><p>Crontab syntax defines scheduled tasks (cron jobs) using a single line with five time-and-date fields followed by the command to execute. Special operators add flexibility when you define time intervals.<\/p><p>Here&rsquo;s the basic format of a crontab entry:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">minute hour day_of_month month day_of_week command_to_execute<\/pre><h3 class=\"wp-block-heading\" id=\"h-the-five-timing-fields-minute-hour-date\">The five timing fields (minute, hour, date)<\/h3><p>The five timing fields define when a cron job runs. The system reads the schedule in the following order:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Field<\/strong><\/td><td><strong>Description<\/strong><\/td><td><strong>Allowed values<\/strong><\/td><\/tr><tr><td><strong>Minute<\/strong><\/td><td>The minute of the hour when the command runs.<\/td><td>0&ndash;59<\/td><\/tr><tr><td><strong>Hour<\/strong><\/td><td>The hour of the day in 24-hour format.<\/td><td>0&ndash;23<\/td><\/tr><tr><td><strong>Day of month<\/strong><\/td><td>The specific date of the month.<\/td><td>1&ndash;31<\/td><\/tr><tr><td><strong>Month<\/strong><\/td><td>The month of the year.<\/td><td>1&ndash;12 or JAN&ndash;DEC<\/td><\/tr><tr><td><strong>Day of week<\/strong><\/td><td>The day of the week.<\/td><td>0&ndash;6, where Sunday = 0 (or 7 on some systems)<\/td><\/tr><\/tbody><\/table><\/figure><p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> Be careful when scheduling jobs across multiple servers in different time zones. Always check each server&rsquo;s local time with the <strong>date<\/strong> command to confirm your configuration is correct.\n            <\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-crontab-operators\">Crontab operators<\/h3><p>Crontab operators let you define complex intervals and patterns within the timing fields. Cronie and its predecessor, Vixie cron, support eight operators.<\/p><p>These implementations serve as the default cron tools on most Linux distributions, including Ubuntu, Debian, RHEL, CentOS, and Fedora:<\/p><ul class=\"wp-block-list\">\n<li><strong>Asterisk (*)<\/strong>. Represents all possible values. For example, an asterisk in the minute field means the job runs every minute.<\/li>\n\n\n\n<li><strong>Comma (,)<\/strong>. Specifies a list of unique values. For example, <strong>1,5<\/strong> in the day of week field runs the task on Monday and Friday.<\/li>\n\n\n\n<li><strong>Hyphen (-)<\/strong>. Defines a range of values. For example, <strong>6-9<\/strong> in the month field runs the job from June to September.<\/li>\n\n\n\n<li><strong>Slash (\/)<\/strong>. Specifies step values or increments. For example, <strong>*\/12<\/strong> in the hour field runs the command every 12 hours.<\/li>\n<\/ul><p>These operators are not supported by standard Linux cron. They work only in Java-based schedulers, such as Quartz and Spring Boot, or cloud services like AWS EventBridge:<\/p><ul class=\"wp-block-list\">\n<li><strong>Last (L)<\/strong>. Specifies the last day of the month or the last occurrence of a weekday.<\/li>\n\n\n\n<li><strong>Weekday (W)<\/strong>. Finds the nearest weekday (Monday&ndash;Friday) to a given date.<\/li>\n\n\n\n<li><strong>Hash (#)<\/strong>. Specifies the nth occurrence of a weekday, such as the second Monday of the month.<\/li>\n\n\n\n<li><strong>Question mark (?)<\/strong>. Indicates that the day of month or day of week does not matter.<\/li>\n<\/ul><p>\n\n\n        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    &#128161; Pro tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\">Most cron implementations let you combine ranges with step values. For example, <strong>1-20\/2<\/strong> runs a job every two minutes during the first 20 minutes.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-cron-job-examples\">Cron job examples<\/h3><p>The following examples show how to apply crontab syntax to real-world tasks.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Cron syntax<\/strong><\/td><td><strong>Purpose<\/strong><\/td><td><strong>Explanation<\/strong><\/td><\/tr><tr><td><strong>0 0 * * 0 \/root\/backup.sh<\/strong><\/td><td>Weekly backup<\/td><td>Runs the backup script every Sunday at midnight.<\/td><\/tr><tr><td><strong>0 * * * 1 \/root\/clearcache.sh<\/strong><\/td><td>Server maintenance<\/td><td>Clears the cache every hour, but only on Mondays.<\/td><\/tr><tr><td><strong>0 6,18 * * * \/root\/db-dump.sh<\/strong><\/td><td>Database snapshot<\/td><td>Dumps the database twice a day at 6 AM and 6 PM.<\/td><\/tr><tr><td><strong>*\/10 * * * * \/scripts\/monitor.sh<\/strong><\/td><td>Uptime monitoring<\/td><td>Runs a monitoring script every 10 minutes.<\/td><\/tr><tr><td><strong>0 0 1,15 * * \/scripts\/payroll.php<\/strong><\/td><td>Bi-monthly task<\/td><td>Runs a payroll script on the 1st and 15th of every month at midnight.<\/td><\/tr><tr><td><strong>30 2 * * * \/usr\/bin\/apt update<\/strong><\/td><td>System update<\/td><td>Checks for package updates daily at 2:30 AM, which is usually a low-traffic time.<\/td><\/tr><tr><td><strong>* * * * \/scripts\/s1.sh; \/scripts\/s2.sh<\/strong><\/td><td>Multiple tasks<\/td><td>Runs multiple commands in a single cron job by separating them with a semicolon.<\/td><\/tr><tr><td><strong>0 8 1-7 * * [ &ldquo;$(date &lsquo;+\\%u&rsquo;)&rdquo; = &ldquo;1&rdquo; ] &amp;&amp; \/scripts\/report.sh<\/strong><\/td><td>Monthly report<\/td><td>Generates a report at 8 AM on days 1&ndash;7 of the month, but only executes the script when it&rsquo;s Monday.<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\" id=\"h-what-are-cron-job-special-strings\">What are cron job special strings?<\/h2><p>Special strings are <strong>shortcuts that start with @ and replace the five-field syntax<\/strong>. They improve readability for common schedules and reduce the risk of syntax errors.<\/p><ul class=\"wp-block-list\">\n<li><strong>@reboot<\/strong>. Runs the command once when the cron daemon starts.<\/li>\n\n\n\n<li><strong>@hourly<\/strong>. Runs once an hour (equivalent to <strong>0 * * * *<\/strong>).<\/li>\n\n\n\n<li><strong>@daily<\/strong> (or <strong>@midnight<\/strong>). Runs once a day at midnight (equivalent to <strong>0 0 * * *<\/strong>).<\/li>\n\n\n\n<li><strong>@weekly<\/strong>. Runs once a week on Sunday at midnight (equivalent to <strong>0 0 * * 0<\/strong>).<\/li>\n\n\n\n<li><strong>@monthly<\/strong>. Runs once a month on the 1st at midnight (equivalent to <strong>0 0 1 * *<\/strong>).<\/li>\n\n\n\n<li><strong>@yearly<\/strong> (or <strong>@annually<\/strong>). Runs once a year on January 1st (equivalent to <strong>0 0 1 1 *<\/strong>).<\/li>\n<\/ul><p>Here are a few examples of cron jobs using special strings:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@daily \/home\/user\/scripts\/daily-cleanup.sh\n@reboot \/usr\/local\/bin\/start-my-app.sh\n@hourly \/var\/www\/html\/monitor.php<\/pre><p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> The <strong>@reboot<\/strong> directive runs when the cron daemon starts, not necessarily when the system boots. If you stop and restart the cron service without rebooting the system, <strong>@reboot<\/strong> jobs run again.\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-cron-permissions\">Cron permissions<\/h2><p>System administrators control who can schedule cron jobs using two files in the <strong>\/etc\/<\/strong> directory: <strong>cron.allow<\/strong> and <strong>cron.deny<\/strong>.<\/p><ul class=\"wp-block-list\">\n<li><strong>cron.allow<\/strong>. If this file exists, only the users listed in it can create, edit, or run cron jobs. The system blocks all other users.<\/li>\n\n\n\n<li><strong>cron.deny<\/strong>. If <strong>cron.allow<\/strong> doesn&rsquo;t exist, the system checks this file instead. Users listed here cannot use cron, while all other users can.<\/li>\n<\/ul><p>If neither file exists, the default behavior depends on the distribution:<\/p><ul class=\"wp-block-list\">\n<li><strong>Debian and Ubuntu<\/strong>. All users can use cron by default.<\/li>\n\n\n\n<li><strong>RHEL, CentOS, and Fedora<\/strong>. Only root can use cron by default.<\/li>\n<\/ul><p>Always check your distribution&rsquo;s documentation or test cron access with a non-root user.<\/p><p>For example, to allow only a database administrator (<strong>dbadmin<\/strong>) to schedule tasks, create a <strong>cron.allow<\/strong> file and add <strong>dbadmin<\/strong> to it. This setup prevents other users from running unauthorized background tasks that consume system resources.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-set-up-a-cron-job\">How to set up a cron job<\/h2><p>To set up a cron job, open your machine&rsquo;s terminal, confirm that cron is installed, create or edit a crontab file with <strong>crontab -e<\/strong>, and view your scheduled tasks with <strong>crontab -l<\/strong>.<\/p><p>Some jobs may require elevated or root privileges, or you may need to place scripts in system directories for recurring tasks.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-access-the-terminal-or-ssh\">1. Access the terminal or SSH<\/h3><p>To manage cron jobs, access your server&rsquo;s command line. If you use a remote server or VPS, connect through SSH with a client such as <a href=\"\/tutorials\/how-to-use-putty-ssh\/\">PuTTY<\/a> on Windows or Terminal on macOS or Linux.<\/p><p>Alternatively, <a href=\"\/vps-hosting\">Hostinger VPS<\/a> users can use the <strong>browser terminal<\/strong> feature available in the VPS dashboard of hPanel.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"6a57fadf7abe4\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a57fadf7abe4\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2088\" height=\"922\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=1024,h=1024,fit=scale-down\" alt=\"Hostinger hPanel VPS overview with browser terminal highlighted\" class=\"wp-image-137461\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=2088,fit=scale-down 2088w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-overview-terminal-highlighted.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2088px) 100vw, 2088px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\" id=\"h-2-install-cron\">2. Install cron<\/h3><p>Most Linux distributions include cron by default. To confirm that it&rsquo;s installed and running, check the service status:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl status cron<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"6a57fadf7d497\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a57fadf7d497\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2286\" height=\"626\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=1024,h=1024,fit=scale-down\" alt=\"Terminal showing cron service active and running status\" class=\"wp-image-137507\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=2286,fit=scale-down 2286w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-systemctl-status-cron-active-running-highlighted.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2286px) 100vw, 2286px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div><p>If the service is missing, install it with your package manager.<\/p><ul class=\"wp-block-list\">\n<li>For Ubuntu and Debian:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt install cron<\/pre><ul class=\"wp-block-list\">\n<li>For RHEL, CentOS, and Fedora:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo dnf install cronie\nsudo systemctl enable crond\nsudo systemctl start crond<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-create-or-edit-a-crontab-file\">3. Create or edit a crontab file<\/h3><p>The main way to schedule tasks is with the crontab command. To create a new crontab file or edit an existing one, run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">crontab -e<\/pre><p>If your system doesn&rsquo;t already have a crontab file for your user, this command creates one automatically.<\/p><p>If this is your first time running the command, the system prompts you to choose a text editor, such as <strong>nano<\/strong> or <strong>vim<\/strong>. <a href=\"\/tutorials\/how-to-install-and-use-nano-text-editor\/\">nano<\/a> is usually easier for beginners.<\/p><p>Once the file opens, add your scheduled task on a new line.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"6a57fadf7ef97\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a57fadf7ef97\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2560\" height=\"1549\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=1024,h=1024,fit=scale-down\" alt=\"Nano editor open with a crontab file in the terminal\" class=\"wp-image-137508\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=2560,fit=scale-down 2560w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-nano-tmp-crontab-scaled.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div><p>For a detailed breakdown of cron syntax, see our guide on <a href=\"\/tutorials\/crontab-syntax\/\">how to write crontab commands<\/a>.<\/p><p>\n\n\n        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    &#128161; Pro tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\">Before scheduling a cron job, test your script manually to confirm it works. Run the script directly over SSH, for example <strong>.\/backup.sh<\/strong>. If it doesn&rsquo;t run manually, it won&rsquo;t run through cron either.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-4-view-scheduled-tasks\">4. View scheduled tasks<\/h3><p>To view the cron jobs scheduled for your user account without editing them, use the list flag:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">crontab -l<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"6a57fadf8070f\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a57fadf8070f\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1878\" height=\"1410\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=1024,h=1024,fit=scale-down\" alt=\"Terminal showing crontab -l output with a scheduled apt update\" class=\"wp-image-137509\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=1878,fit=scale-down 1878w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-l-apt-update-highlighted.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1878px) 100vw, 1878px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div><p>To view the cron jobs for a specific user, run the following command and replace username with the appropriate account name. Note that this requires root or elevated privileges.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo crontab -u username -l<\/pre><h3 class=\"wp-block-heading\" id=\"h-5-grant-root-access-if-needed\">5. Grant root access if needed<\/h3><p>Some commands, such as system updates or changes to system-wide configuration files, require root privileges. The simplest way to schedule these tasks is to add them to the root user&rsquo;s crontab:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo crontab -e<\/pre><p>Any command in root&rsquo;s crontab runs with root privileges and requires no additional configuration.<\/p><p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> Avoid running tasks as root unless necessary. If a script only needs access to specific files or directories, consider adjusting file ownership with the <a href=\"\/tutorials\/linux-chown-command\/\">chown command<\/a> or using a dedicated service account instead.\n            <\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-6-use-cron-directories-for-recurring-scripts\">6. Use cron directories for recurring scripts<\/h3><p>For general maintenance scripts that don&rsquo;t need to run at a specific minute, you can place them in predefined system directories. The system automatically runs executable scripts found in these locations:<\/p><ul class=\"wp-block-list\">\n<li><strong>\/etc\/cron.hourly\/<\/strong><\/li>\n\n\n\n<li><strong>\/etc\/cron.daily\/<\/strong><\/li>\n\n\n\n<li><strong>\/etc\/cron.weekly\/<\/strong><\/li>\n\n\n\n<li><strong>\/etc\/cron.monthly\/<\/strong><\/li>\n<\/ul><p>To run correctly, scripts in these directories must have executable permissions and follow the <strong>run-parts<\/strong> naming rules:<\/p><ul class=\"wp-block-list\">\n<li>Filenames can include only uppercase and lowercase letters, digits, underscores (<strong>_<\/strong>), and hyphens (<strong>&ndash;<\/strong>).<\/li>\n\n\n\n<li>Filenames must not use file extensions. For example, a script named <strong>backup.sh<\/strong> will be ignored. Rename it to <strong>backup<\/strong> instead.<\/li>\n\n\n\n<li>Filenames must not contain dots (<strong>.<\/strong>) anywhere. For example, <strong>my.script<\/strong> will fail silently, which is a common source of errors.<\/li>\n<\/ul><h3 class=\"wp-block-heading\" id=\"h-7-delete-scheduled-tasks\">7. Delete scheduled tasks<\/h3><p>To remove all cron jobs for the current user, use the remove flag:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">crontab -r<\/pre><p>Because this command deletes all entries instantly, it&rsquo;s safer to combine it with the interactive (<strong>-i<\/strong>) flag. This option asks for confirmation before removing all scheduled tasks:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">crontab -ri<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"6a57fadf8216b\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a57fadf8216b\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1682\" height=\"148\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=1024,h=1024,fit=scale-down\" alt=\"Terminal prompting confirmation for crontab -ri command\" class=\"wp-image-137510\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=1682,fit=scale-down 1682w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/09\/terminal-crontab-ri.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1682px) 100vw, 1682px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div><p>\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> The <strong>-i<\/strong> flag works only when used with <strong>-r<\/strong>. Running <strong>crontab -i<\/strong> by itself has no effect.\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-s-the-next-step-after-scheduling-tasks-with-cron\"><strong>What&rsquo;s the next step after scheduling tasks with cron?<\/strong><\/h2><p>Cron jobs automate recurring tasks by combining the cron daemon (which runs continuously), the crontab file (which sets the schedule), and the command that performs the work. This automation is essential for efficient system management and handling routine tasks without manual intervention.<\/p><p>However, cron jobs are only as powerful as the scripts they run. The cron daemon triggers commands at set times, but your script does the actual work. And if the script contains errors, the task will fail even if the cron job runs successfully.<\/p><p>Learning to write efficient Bash scripts lets you automate complex and valuable tasks via cron. Check out our <a href=\"https:\/\/www.hostinger.com\/tutorials\/bash-script-example\/\">Bash script tutorial<\/a> to get started.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A cron job is a time-based scheduler in Unix-like operating systems, such as Linux and macOS. It automates repetitive tasks [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/cron-job\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":27,"featured_media":87036,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Cron job: What it is and how to configure it in %currentyear%","rank_math_description":"A cron job is an automated task run by cron, a scheduling tool for Unix-like systems. Learn how cron jobs work and how to set them up.","rank_math_focus_keyword":"cron job","footnotes":""},"categories":[22644,22648],"tags":[],"class_list":["post-18211","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps","category-managing-monitoring-and-security"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/cron-job","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/cron-job-guia","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/cron-job","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/cron-job","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cron-job","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/cron-job","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/cron-job","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/cron-job","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/cron-job","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/cron-job","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/cron-job","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/cron-job-guia","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/cron-job","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/cron-job","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/cron-job","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/cron-job","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/18211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=18211"}],"version-history":[{"count":61,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/18211\/revisions"}],"predecessor-version":[{"id":137597,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/18211\/revisions\/137597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/87036"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=18211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=18211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=18211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}