Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

What Is a Cron Job and How to Use It on a Linux VPS

A practical Linux VPS guide to cron jobs: create and verify crontabs, understand five-field schedules, make scripts reliable, diagnose missed runs, and decide when systemd timers are better.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A cron job is a command that a Linux scheduling daemon runs at defined times. On a VPS, cron is commonly used for backups, log cleanup, certificate checks, database maintenance, and game-server tasks that must happen without an operator present. You define the schedule in a crontab, verify the daemon is running, and make the command observable with deliberate logging or mail. This guide explains the five-field syntax, a safe setup procedure, environment and permission issues, daylight-saving behavior, troubleshooting, and when a systemd timer is a better fit.

What a cron job is

Linux cron is a daemon that examines stored schedules and executes commands whose time matches the current minute. The Linux man-pages project describes crond as the daemon to execute scheduled commands and notes that it checks each stored crontab every minute. A cron job is one scheduled command; a crontab is the table containing one or more jobs and, optionally, environment assignments.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Each user can have a personal crontab. System-wide schedules can also be placed in files such as /etc/crontab and /etc/cron.d/. Personal tables identify the command owner from the file itself, while entries in /etc/cron.d/ include a username field between the time fields and the command. That distinction matters: copying a line from a system file into crontab -e adds an extra field and causes the personal entry to be parsed incorrectly.

A cron daemon does not behave like an interactive terminal. It starts the command with a small environment, a working directory you should not assume, and the permissions of the account that owns the entry. A command that succeeds in your shell can therefore fail under cron unless paths, variables, permissions, and output handling are explicit.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Prepare the VPS before scheduling anything

Identify the daemon and distribution

Service names vary. Debian and Ubuntu commonly use a service named cron; many Red Hat, Fedora, and related images use crond. Check which unit exists instead of assuming:

systemctl status cron
systemctl status crond

Use the command that matches your image. If the service is installed but stopped, an administrator can start and enable it with the corresponding unit, for example sudo systemctl enable --now cron. Some minimal images use a different init system, so consult that distribution’s service documentation when systemctl is unavailable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the account deliberately

Run a job as the least-privileged account that can complete it. A backup that only reads an application directory should not run as root merely because the VPS owner has root access. Running as the application account limits the damage from a compromised script and makes file ownership predictable. Use root only for operations that genuinely require it, such as reading protected system data or restarting a root-owned service.

Confirm time, files, and permissions

Check the VPS clock and timezone before writing a schedule. On systemd-based images, timedatectl displays the configured timezone and synchronization state. Ensure the script exists, has a valid interpreter line such as #!/bin/sh or #!/usr/bin/env bash, and is executable when you invoke it directly. Create a log destination that the selected account can write to; a personal job usually cannot append to a root-owned file under /var/log.

Install your first cron job

  1. Open the intended user’s table. Log in as that account, or switch to it, then run crontab -e. The editor saves a user crontab; do not edit files in the cron spool directory directly.
  2. Add a complete schedule and command. This example runs a backup script every day at 02:15 and appends both standard output and errors to a log:
    15 2 * * * /usr/local/bin/backup.sh >>/var/log/backup.log 2>&1

    If the account cannot write /var/log/backup.log, place the log in a directory it owns or arrange an administrator-managed log file with suitable permissions.

  3. Save and exit the editor. Cron normally notices a changed table automatically; a daemon restart is not normally required merely because you changed a crontab.
  4. Verify the installed entry. Run crontab -l as the same account. This confirms that you edited the intended user’s table and that the line was accepted.
  5. Test the command outside the schedule. Execute the exact command with its absolute paths as the same user. Testing first separates script failures from scheduling failures.

Use a harmless test schedule when you need to prove execution quickly, such as * * * * * /usr/bin/date >>/home/youruser/cron-test.log 2>&1. Watch the file for a few minutes, then remove the test line with crontab -e. Replace /home/youruser with the real home directory; do not leave a per-minute test running on a production VPS.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Understand the five cron fields

A standard personal crontab line has five time fields followed by the command. POSIX defines the order and the numeric ranges shown below.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Field Allowed values Example Meaning of the example
Minute 0–59 15 At minute 15
Hour 0–23 2 At 02:00 through 02:59, constrained by the minute field
Day of month 1–31 * Every calendar day of the month
Month 1–12 * Every month
Day of week 0–6 * Every weekday value; Sunday is 0, and some implementations also accept 7 for Sunday

An asterisk means all permitted values. A comma creates a list, a hyphen creates an inclusive range, and */n creates steps within the field:

  • 0,30 in the minute field runs at the top and halfway through each hour.
  • 1-5 in the day-of-week field selects Monday through Friday on implementations where Monday is 1.
  • */15 in the minute field runs every 15 minutes: 0, 15, 30, and 45.
  • 0 3 1 * * runs at 03:00 on the first day of each month.

For example, a weekday maintenance script at 03:30 is:

30 3 * * 1-5 /usr/local/bin/maintenance.sh

When both day-of-month and day-of-week are restricted rather than set to *, behavior around the two conditions differs among cron implementations. Read the local crontab(5) manual and test an unambiguous schedule if the distinction matters. Avoid relying on a complicated expression for a business-critical date without verifying it on the VPS.

Short Linux schedules

Linux cron implementations commonly provide nicknames for frequent schedules:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
  • @reboot runs when the cron daemon starts, not necessarily after every service on the VPS is ready.
  • @hourly runs once per hour.
  • @daily runs once per day.
  • @weekly runs once per week.
  • @monthly runs once per month.
  • @yearly runs once per year.

Use the five fields when the exact minute, timezone expectation, or calendar rule needs to be obvious to another administrator.

Make commands reliable in cron’s restricted environment

Use absolute paths and set variables

Interactive shells often set PATH, HOME, language settings, credentials, and aliases. Cron may provide none of those values, or provide different ones. Call binaries by absolute path, such as /usr/bin/rsync rather than relying on a shell search path. If a script needs a particular environment, define it at the top of the crontab or inside the script:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[email protected]

Only set variables that are appropriate for the account. Keep secrets out of a world-readable crontab; use a protected configuration file, a credential store, or a file readable only by the service account. Quote paths and arguments that contain spaces or shell metacharacters. A script should also change to its intended working directory explicitly, for example with cd /srv/game-server && ....

Make the script executable and self-contained

Check the shebang, executable bit, line endings, and interpreter location. A script copied from another machine can contain Windows line endings or refer to an interpreter that is absent on the VPS. Call the script with its full path and use set -e or explicit error checks when silent partial completion would be dangerous. Cron cannot repair a script that exits successfully after an internal failure, so make the script return a nonzero status when work did not complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture both output streams

Cron can send command output to the job owner by mail and can also write daemon information to syslog. Relying on either channel without checking it leaves failures hidden. Redirect intentionally:

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
15 2 * * * /usr/local/bin/backup.sh >>/srv/log/backup.log 2>&1

The >> operator appends, while 2>&1 sends standard error to the same destination as standard output. Rotate or prune growing logs, and ensure the destination directory has the correct owner and mode. If mail is useful on your image, set MAILTO and verify that a local mail transport is configured; otherwise a successful-looking cron line may still produce no deliverable message.

Useful VPS scheduling patterns

Nightly backups

Keep the schedule, script, and log separate so each can be tested. A typical entry is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
15 2 * * * /usr/local/bin/backup.sh >>/srv/log/backup.log 2>&1

The script should check source and destination availability, report a nonzero exit status on failure, and avoid deleting the only available copy before a new archive is verified. The cron line itself should stay simple enough to inspect with crontab -l.

Game-server maintenance

For a game server or web application, use an explicit working directory and a wrapper script rather than embedding a long chain of shell commands in the crontab:

0 5 * * 0 /usr/local/bin/weekly-server-maintenance.sh >>/srv/game-server/log/maintenance.log 2>&1

The wrapper can check that the service is healthy, create a backup, apply updates, and return a failure code if any stage fails. Do not assume that a process started by cron inherits the same user, socket, or environment as a process launched by your deployment tool.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Prevent overlapping runs

Cron starts a new process when a matching minute arrives; it does not automatically wait for the previous run to finish. Long backups, update jobs, and slow database exports can overlap and corrupt output or overload a small VPS. Add an appropriate locking strategy in the script or use a locking utility such as flock where it is available. The lock must have a clear stale-lock policy and should not hide a real failure. If the job needs service dependencies, resource limits, or ordered startup, a systemd service and timer generally provide stronger controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Timezone and daylight-saving behavior

Cron evaluates schedules in the local time context used by the daemon. During a daylight-saving transition, a local time that does not exist can be skipped. When the clock repeats an hour, a job scheduled in that repeated interval can run twice. This is documented cron behavior, not evidence that the daemon randomly lost a schedule.

For work that must occur at a consistent instant, standardize the VPS timezone and document it, or choose a scheduling mechanism whose timezone behavior you have verified. Test dates around the daylight-saving transition relevant to the server’s region. A monthly billing, backup, or restart task should be designed to tolerate a duplicate invocation or to detect that the intended period was already processed.

Where to look when a job did not run

  1. Confirm the table and account. Run crontab -l as the intended user. If the entry was installed with sudo crontab -e, it belongs to root and will not appear in an ordinary user’s listing.
  2. Run the exact command manually. Use the same absolute paths and account. If it fails interactively, fix the script, permissions, or inputs before investigating cron.
  3. Check the daemon. Inspect systemctl status cron or systemctl status crond, whichever exists. A disabled, stopped, or repeatedly failing service cannot launch entries.
  4. Inspect logs and mail. Look in the distribution’s cron log or system journal, then inspect the file named in your output redirection. Cron’s documented output paths are mail to the owner and syslog; a missing log file may simply mean the command could not open its destination.
  5. Check file details. Verify the script’s executable bit, shebang, interpreter path, ownership, directory traversal permissions, and required credentials. Confirm that the crontab ends with a newline; the crontab(5) manual warns that a missing final newline can leave a table partially broken.
  6. Check the environment. Replace relative paths, set PATH and other required variables, and specify the working directory. A command that depends on an interactive shell profile will often fail under cron.
  7. Check timing and overlap. Confirm the VPS timezone, daylight-saving transition, and whether an earlier invocation is still running or holding a lock.
  8. Inspect systemd translations when applicable. Debian’s systemd-cron tooling can translate cron entries into systemd service and timer units. Use systemctl list-timers to see timer activity and journalctl -u <unit> to inspect the generated unit’s log. The exact unit name depends on the entry and package configuration.

Common failure symptoms

  • No entry in crontab -l: the line was saved under another account, rejected by the editor, or removed during an image rebuild. Reopen the correct user’s table.
  • Manual run works, cron run fails: compare environment variables, current directory, permissions, and absolute command paths. Add temporary diagnostic output to the log.
  • Log file is empty: verify that the command reached the redirection, that the directory is writable, and that the schedule has reached its next matching minute.
  • Two copies run: the interval is shorter than the job duration or a previous invocation was retried. Add locking and make the operation idempotent.
  • It ran at an unexpected hour: inspect the VPS timezone and daylight-saving transition rather than changing the numeric hour blindly.

Cron versus a systemd timer

Cron remains attractive because its five fields are compact and available across a wide range of Linux distributions. Native systemd timers are more integrated with systemd services and expose dependency, logging, calendar, and resource controls. Debian’s systemd-cron documentation also describes translating cron entries into timer and service units, allowing administrators to inspect activity with systemd tools. Package behavior and generated unit names depend on the VPS distribution.

Consideration Cron Native systemd timer
Portability Compact syntax is widely available on Linux distributions. Requires systemd and its unit model.
Calendar expressions Five numeric fields, lists, ranges, steps, and common nicknames. Calendar expressions can describe richer schedules.
Dependencies and ordering Requires the command or script to implement readiness checks. Can express service dependencies and ordering through unit relationships.
Logging and inspection Output is commonly mailed or sent to syslog; you must arrange useful redirection. systemctl list-timers and journalctl provide timer and service evidence.
Failure handling Scripts must report status, retry, and prevent overlap themselves. Service units expose systemd restart and state-management features.
Resource controls Limited to what the invoked command and surrounding tools enforce. Can use systemd’s service-level resource and execution controls.

Choose cron for a small, portable schedule whose command can run independently. Choose a native systemd timer when startup ordering, service state, journal evidence, missed-run behavior, or resource controls are central requirements. On a Debian image using systemd-cron, understand whether you are managing the original crontab, generated units, or both before changing a production schedule.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Operational checklist for production cron

  • Install the entry with crontab -e and verify it with crontab -l under the intended account.
  • Use absolute paths, an explicit interpreter, and an explicit working directory.
  • Run with the least privilege that can complete the task.
  • Set required variables instead of assuming an interactive shell profile.
  • Redirect standard output and standard error, or configure and test MAILTO.
  • Keep logs bounded and monitor them for nonzero exit messages.
  • Use locking and idempotent scripts for jobs that can overlap.
  • Document the VPS timezone and account for skipped or repeated daylight-saving times.
  • Check the cron service, logs, permissions, and final newline when a job appears to be missing.
  • Move to a systemd timer when dependencies, journal integration, service lifecycle, or resource controls outweigh cron’s portability.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.