{"id":14669,"date":"2025-12-27T11:25:17","date_gmt":"2025-12-27T05:55:17","guid":{"rendered":"https:\/\/www.youstable.com\/blog\/?p=14669"},"modified":"2025-12-27T11:25:19","modified_gmt":"2025-12-27T05:55:19","slug":"cron-job-examples-for-sysadmins","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/cron-job-examples-for-sysadmins","title":{"rendered":"Top Cron Job Examples for Sysadmins to Automate Linux Servers"},"content":{"rendered":"\n<p>Cron job examples are ready-made scheduling patterns and commands that sysadmins can copy, adapt, and run via crontab to automate backups, updates, monitoring, and maintenance. Below are practical, production-tested cron job examples with best practices for reliability, security, and performance so your Linux servers run the right tasks on time, every time.<\/p>\n\n\n\n<p>If you manage Linux servers, learning cron job examples is one of the highest-ROI skills you can build. Cron automates repetitive tasks\u2014backups, log cleanup, SSL renewals, patching, and WordPress maintenance freeing you from manual chores and reducing risk. This guide distills 15+ years of sysadmin practice into safe, copy-paste crontab examples with explanations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"how-cron-works-quick-primer\"><strong>How Cron Works (Quick Primer)<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.youstable.com\/blog\/use-cron-jobs-on-linux\/\">Cron is a time-based job scheduler<\/a>. The cron daemon reads system-wide and per-user crontab files, then executes commands at defined times. It\u2019s simple, lightweight, and ubiquitous on Linux and Unix-like systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"where-cron-reads-jobs\"><strong>Where Cron Reads Jobs<\/strong><\/h2>\n\n\n\n<p><strong>Common locations include:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>User crontabs:<\/strong> managed via <code>crontab -e<\/code> (stored under <code>\/var\/spool\/cron\/<\/code>)<\/li>\n\n\n\n<li><strong>System crontab: <\/strong><code>\/etc\/crontab<\/code><\/li>\n\n\n\n<li><strong>Drop-in files: <\/strong><code>\/etc\/cron.d\/<\/code> (package or service-specific)<\/li>\n\n\n\n<li><strong>Periodic directories: <\/strong><code>\/etc\/cron.hourly<\/code>, <code>\/etc\/cron.daily<\/code>, <code>\/etc\/cron.weekly<\/code>, <code>\/etc\/cron.monthly<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"crontab-syntax-minute-to-weekday\"><strong>Crontab Syntax (Minute to Weekday)<\/strong><\/h3>\n\n\n\n<p>Crontab uses five time fields followed by the command. Asterisks match all values; commas list values; dashes define ranges; slashes set steps.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u250c\u2500 minute (0-59)\n# \u2502 \u250c\u2500 hour (0-23)\n# \u2502 \u2502 \u250c\u2500 day of month (1-31)\n# \u2502 \u2502 \u2502 \u250c\u2500 month (1-12)\n# \u2502 \u2502 \u2502 \u2502 \u250c\u2500 day of week (0-7, Sun=0 or 7)\n# \u2502 \u2502 \u2502 \u2502 \u2502\n# * * * * *  command-to-run\n\n# Special strings:\n@reboot  command\n@yearly  command\n@monthly command\n@weekly  command\n@daily   command\n@hourly  command<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"cron-best-practices-before-you-start\"><strong>Cron Best Practices Before You Start<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"set-environment-and-use-absolute-paths\"><strong>Set Environment and Use Absolute Paths<\/strong><\/h3>\n\n\n\n<p>Cron runs with a minimal environment. Always set PATH, use absolute paths, and log output. Prefer using a wrapper script for complex tasks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># In your crontab (crontab -e)\nSHELL=\/bin\/bash\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\nMAILTO=admin@example.com\n# Log both stdout and stderr:\n# command &gt;&gt; \/var\/log\/cron\/myjob.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"avoid-duplicate-runs-with-flock\"><strong>Avoid Duplicate Runs with flock<\/strong><\/h3>\n\n\n\n<p>Ensure only one instance runs at a time by locking the job. This prevents overlap on slow or busy servers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/5 * * * * flock -n \/var\/lock\/myjob.lock \/usr\/local\/bin\/myjob.sh &gt;&gt; \/var\/log\/cron\/myjob.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"plan-for-timezones-dst-and-non-24-7-hosts\"><strong>Plan for Timezones, DST, and Non-24\/7 Hosts<\/strong><\/h3>\n\n\n\n<p>Schedule in UTC to avoid DST surprises. For laptops or VMs that don\u2019t run 24\/7, use anacron. On modern distros, consider systemd timers for richer control and calendar semantics.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"privilege-and-security\"><strong>Privilege and Security<\/strong><\/h3>\n\n\n\n<p>Run as the least-privileged user possible, sanitize inputs, quote variables, and avoid shell wildcards that may expand unpredictably. Keep secrets in root-readable files and reference them securely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"top-cron-job-examples-for-sysadmins\"><strong>Top Cron Job Examples for Sysadmins<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"1-nightly-server-backups-rsync\"><strong>1) Nightly Server Backups (rsync)<\/strong><\/h3>\n\n\n\n<p>Mirror key directories to a backup disk or NAS. Combine with rotation (e.g., via date-stamped dirs) and offsite sync.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 2 * * * flock -n \/var\/lock\/backup.lock rsync -aHAX --delete \/srv\/ \/backup\/srv\/ &gt;&gt; \/var\/log\/cron\/backup.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"2-encrypted-incremental-backups-restic\"><strong>2) Encrypted Incremental Backups (Restic)<\/strong><\/h3>\n\n\n\n<p>Push encrypted snapshots to object storage (S3, B2). Ensure environment variables are set via a sourced file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>15 2 * * * . \/root\/.restic-env; flock -n \/var\/lock\/restic.lock restic backup \/var\/www \/etc --verbose &amp;&amp; restic forget --keep-daily 7 --keep-weekly 4 --prune &gt;&gt; \/var\/log\/cron\/restic.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"3-mysql-mariadb-hot-dumps\"><strong>3) MySQL\/MariaDB Hot Dumps<\/strong><\/h3>\n\n\n\n<p>Create compressed, dated dumps and prune old ones. Store credentials in <code>\/root\/.my.cnf<\/code> with strict permissions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>30 1 * * * mkdir -p \/backup\/db &amp;&amp; mysqldump --all-databases | gzip &gt; \/backup\/db\/mysql-$(date +\\%F).sql.gz &amp;&amp; find \/backup\/db -name 'mysql-*.sql.gz' -mtime +14 -delete<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"4-postgresql-dumps\"><strong>4) PostgreSQL Dumps<\/strong><\/h3>\n\n\n\n<p>Use <code>pg_dumpall<\/code> or per-database <code>pg_dump<\/code>. Ensure proper PG environment variables or .pgpass file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>40 1 * * * mkdir -p \/backup\/db &amp;&amp; pg_dumpall -U postgres | gzip &gt; \/backup\/db\/postgres-$(date +\\%F).sql.gz &amp;&amp; find \/backup\/db -name 'postgres-*.sql.gz' -mtime +14 -delete<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"5-lets-encrypt-certificate-renewal-certbot\"><strong>5) Let\u2019s Encrypt Certificate Renewal (Certbot)<\/strong><\/h3>\n\n\n\n<p>Renew SSL certificates twice daily and reload the web server if renewal occurs. Many distros install a timer, but cron works too.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 *\/12 * * * certbot renew --quiet --deploy-hook \"systemctl reload nginx\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"6-unattended-security-updates\"><strong>6) Unattended Security Updates<\/strong><\/h3>\n\n\n\n<p>On Debian\/Ubuntu, prefer <code>unattended-upgrades<\/code>. If you must use cron, schedule updates and log output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>20 3 * * * apt-get update &amp;&amp; DEBIAN_FRONTEND=noninteractive apt-get -y upgrade &gt;&gt; \/var\/log\/cron\/apt-updates.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"7-log-rotation-trigger-if-needed\"><strong>7) Log Rotation Trigger (if needed)<\/strong><\/h3>\n\n\n\n<p>Most systems rotate logs via logrotate and system timers. If you need a manual cron trigger, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 0 * * * \/usr\/sbin\/logrotate -s \/var\/lib\/logrotate\/status \/etc\/logrotate.conf &gt;&gt; \/var\/log\/cron\/logrotate.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"8-disk-usage-alerts\"><strong>8) Disk Usage Alerts<\/strong><\/h3>\n\n\n\n<p>Send an email when disk usage exceeds a threshold. Adjust the percentage as needed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/15 * * * * df -hP | awk 'NR&gt;1 {if (int($5)&gt;85) print $0}' | mail -s \"Disk Alert on $(hostname)\" admin@example.com<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"9-systemd-service-health-checks-with-auto-restart\"><strong>9) Systemd Service Health Checks with Auto-Restart<\/strong><\/h3>\n\n\n\n<p>Monitor critical services and restart if they\u2019re inactive. Combine with alerting for visibility.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/5 * * * * systemctl is-active --quiet nginx || (systemctl restart nginx &amp;&amp; echo \"Nginx restarted on $(hostname)\" | mail -s \"Nginx Restarted\" admin@example.com)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"10-clean-temporary-and-cache-files\"><strong>10) Clean Temporary and Cache Files<\/strong><\/h3>\n\n\n\n<p>Keep temp and cache directories tidy to reclaim space. Be precise with paths to avoid accidental deletions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>30 3 * * * find \/tmp -type f -mtime +3 -delete\n0 4 * * 0 find \/var\/cache -type f -mtime +7 -delete<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"11-journal-cleanup\"><strong>11) Journal Cleanup<\/strong><\/h3>\n\n\n\n<p>Prune systemd journal to a sane size and age, keeping logs manageable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>15 4 * * * journalctl --vacuum-size=1G --vacuum-time=14d<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"12-docker-image-and-container-pruning\"><strong>12) Docker Image and Container Pruning<\/strong><\/h3>\n\n\n\n<p>Remove unused Docker resources weekly to save <a href=\"https:\/\/www.youstable.com\/blog\/check-disk-space-files-in-linux\/\">disk space<\/a>. Review before enabling on production hosts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 5 * * 0 docker system prune -af --volumes &gt;&gt; \/var\/log\/cron\/docker-prune.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"13-rsync-to-offsite-host\"><strong>13) rsync to Offsite Host<\/strong><\/h3>\n\n\n\n<p>Push critical data to an offsite server over SSH with keys and restricted permissions. <a href=\"https:\/\/www.youstable.com\/blog\/why-should-you-consider-windows-dedicated-server-hosting\/\">Consider bandwidth windows<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 1 * * * rsync -a --delete -e \"ssh -i \/root\/.ssh\/backup_key\" \/backup\/ backupuser@offsite.example.com:\/offsite\/$(hostname)\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"14-security-scans-clamav\"><strong>14) Security Scans (ClamAV)<\/strong><\/h3>\n\n\n\n<p>Perform daily antivirus scans of web roots and quarantine infected files for review.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>30 2 * * * clamscan -ri \/var\/www --log=\/var\/log\/clamav\/daily_scan.log --move=\/var\/quarantine\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"15-configuration-drift-detection\"><strong>15) Configuration Drift Detection<\/strong><\/h3>\n\n\n\n<p>Detect unauthorized changes with checksums of key directories and email differences.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/30 * * * * (cd \/etc &amp;&amp; sha256sum -b $(find . -type f) | sort | sha256sum) | diff -q - \/root\/.etc.sha256 || (echo \"Config drift on $(hostname)\" | mail -s \"Config Drift\" admin@example.com); (cd \/etc &amp;&amp; sha256sum -b $(find . -type f) | sort | sha256sum &gt; \/root\/.etc.sha256)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"wordpress-friendly-cron-job-examples\"><strong>WordPress-Friendly Cron Job Examples<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"replace-wp-cron-with-system-cron\"><strong>Replace WP-Cron with System Cron<\/strong><\/h3>\n\n\n\n<p>Disable pseudo-cron (<code>DISABLE_WP_CRON<\/code>) and schedule real cron for consistent performance, especially on busy sites or low-traffic sites where WP-Cron is unreliable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># In <a href=\"https:\/\/www.youstable.com\/blog\/edit-wp-config-php-file-in-wordpress\/\">wp-config.php<\/a>\ndefine('DISABLE_WP_CRON', true);\n\n# System cron (every 5 minutes):\n*\/5 * * * * php -q \/var\/www\/example.com\/public\/wp-cron.php &gt;&gt; \/var\/log\/cron\/wp-cron.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"scheduled-wordpress-tasks-with-wp-cli\"><strong>Scheduled WordPress Tasks with WP-CLI<\/strong><\/h3>\n\n\n\n<p>Trigger scheduled events and maintenance safely via WP-CLI. Useful for multisite or multiple installs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/10 * * * * \/usr\/local\/bin\/wp --path=\/var\/www\/example.com\/public cron event run --due-now &gt;&gt; \/var\/log\/cron\/wp-events.log 2&gt;&amp;1\n0 3 * * 0 \/usr\/local\/bin\/wp --path=\/var\/www\/example.com\/public cache flush<\/code><\/pre>\n\n\n\n<p>If you host WordPress on YouStable\u2019s managed VPS or cloud, our team can harden WP-Cron, configure WP-CLI tasks, and set up offsite backups with retention\u2014so your jobs run fast and predictably.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"advanced-scheduling-patterns\"><strong>Advanced Scheduling Patterns<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"avoid-thundering-herd-randomize-start\"><strong>Avoid Thundering Herd: Randomize Start<\/strong><\/h3>\n\n\n\n<p>When many servers run the same job, add a random delay to spread load. Use <code>sleep<\/code> with a random number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/5 * * * * sleep $((RANDOM % 300)); \/usr\/local\/bin\/metrics-push.sh<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"every-n-minutes-or-specific-windows\"><strong>Every N Minutes or Specific Windows<\/strong><\/h3>\n\n\n\n<p>Run every 15 minutes during business hours only, and hourly otherwise, by combining entries. Cron supports step values with ranges.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Every 15 minutes 09:00\u201317:59\n*\/15 9-17 * * * \/usr\/local\/bin\/report.sh\n# Hourly outside business hours\n0 0-8,18-23 * * * \/usr\/local\/bin\/report.sh<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"use-atreboot-for-one-time-boot-tasks\"><strong>Use @reboot for One-Time Boot Tasks<\/strong><\/h3>\n\n\n\n<p>Initialize caches or verify mounts after boot. Pair with <code>flock<\/code> to avoid accidental multiple runs during rapid restarts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@reboot flock -n \/var\/lock\/boot-init.lock \/usr\/local\/sbin\/boot-init.sh<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"troubleshooting-cron-jobs\"><strong>Troubleshooting Cron Jobs<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"common-gotchas-and-fixes\"><strong>Common Gotchas and Fixes<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Environment mismatch: <\/strong>export PATH, set SHELL, and source env files if needed.<\/li>\n\n\n\n<li><strong>Permissions:<\/strong> ensure scripts are executable and owned by the correct user.<\/li>\n\n\n\n<li><strong>Shell differences: <\/strong>use <code>\/bin\/bash<\/code> if relying on Bash-isms.<\/li>\n\n\n\n<li><strong>Logging:<\/strong> always capture stdout and stderr to a named log.<\/li>\n\n\n\n<li><strong>Mail alerts: <\/strong>use <code>MAILTO<\/code> or send mail on nonzero exit codes.<\/li>\n\n\n\n<li><strong>Check logs:<\/strong> <code>\/var\/log\/syslog<\/code> or <code>\/var\/log\/cron<\/code> depending on distro, and systemd\u2019s <code>journalctl -u cron<\/code> or <code>-u crond<\/code>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Test as the target user:\nsudo -u www-data \/usr\/local\/bin\/script.sh\n\n# Run the exact crontab command manually:\nSHELL=\/bin\/bash PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin command-here<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"cron-vs-alternatives\"><strong>Cron vs. Alternatives<\/strong><\/h2>\n\n\n\n<p>Cron is lightweight and universal, but systemd timers offer richer calendars, dependencies, and native logging. In containers and Kubernetes, prefer init systems or Kubernetes CronJobs. For cross-cloud workflows, use providers like Cloud Scheduler (GCP) or EventBridge Scheduler (AWS).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"when-to-use-managed-help\"><strong>When to Use Managed Help<\/strong><\/h2>\n\n\n\n<p>If uptime is critical, offload cron design and monitoring to experts. YouStable\u2019s managed hosting can architect resilient schedules (locks, retries, alerts), hardened backups, and safe update pipelines\u2014so your automation is reliable, audited, and documented.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"faqs\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1766048702994\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"what-are-the-most-useful-cron-job-examples-for-linux-servers\"><strong>What are the most useful cron job examples for Linux servers?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Backups (rsync\/restic), database dumps, SSL renewals (certbot), security updates, disk and service health checks, log cleanup, Docker pruning, and WordPress WP-CLI schedules. Start with backups, monitoring, and patching for the biggest impact.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1766048725791\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"how-do-i-run-a-cron-job-every-5-minutes-safely\"><strong>How do I run a cron job every 5 minutes safely?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use <code>*\/5 * * * *<\/code>, add <code>flock<\/code> to prevent overlap, and log output. In fleets, randomize start with <code>sleep $((RANDOM % 300))<\/code> to reduce load spikes.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1766048737482\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"why-does-my-script-work-manually-but-not-from-cron\"><strong>Why does my script work manually but not from cron?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Environment differences: PATH, SHELL, and working directory vary under cron. Use absolute paths, specify the shell, set PATH, and capture errors with <code>2&gt;&amp;1<\/code>. Test as the cron user with <code>sudo -u &lt;user&gt;<\/code>.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1766048750336\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"should-i-use-systemd-timers-instead-of-cron\"><strong>Should I use systemd timers instead of cron?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>For complex schedules, dependencies, and native logging, yes\u2014systemd timers are often superior. Cron remains excellent for simple, portable tasks and in environments without systemd.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1766048763668\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"how-do-i-send-email-alerts-from-cron-jobs\"><strong>How do I send email alerts from cron jobs?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Set <code>MAILTO<\/code> in crontab or pipe output to <code>mail<\/code>\/<code>mailx<\/code>. Ensure an MTA (Postfix\/ssmtp\/msmtp) is configured. For example: <code>... | mail -s \"Subject\" admin@example.com<\/code>.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Cron job examples are ready-made scheduling patterns and commands that sysadmins can copy, adapt, and run via crontab to automate [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":16277,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[350],"tags":[],"class_list":["post-14669","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase"],"acf":[],"featured_image_src":"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2025\/12\/Top-Cron-Job-Examples-for-Sysadmins-to-Automate-Linux-Servers.jpg","author_info":{"display_name":"Sanjeet Chauhan","author_link":"https:\/\/www.youstable.com\/blog\/author\/sanjeet"},"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/14669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=14669"}],"version-history":[{"count":5,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/14669\/revisions"}],"predecessor-version":[{"id":15052,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/14669\/revisions\/15052"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/16277"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=14669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=14669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=14669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}