Scheduled Publishing with Cron for Quartz Sites
Scheduled Publishing with Cron for Quartz Sites
Section titled “Scheduled Publishing with Cron for Quartz Sites”Set up automatic publishing for your Quartz site using cron. Configure twice-daily automatic deployments so your site stays updated without manual intervention.
Table of Contents
Section titled “Table of Contents”- What You’ll Build
- Prerequisites
- Setup Instructions
- Testing Your Cron Jobs
- Monitoring and Maintenance
- Troubleshooting
What You’ll Build
Section titled “What You’ll Build”Automatic publishing system that:
- Publishes your Quartz site twice daily (9 AM and 6 PM)
- Runs on your always-on Mac mini
- No manual intervention needed
- Works alongside your Alfred workflows
- Logs all publish attempts for review
The automated workflow:
Edit in Obsidian → Files sync automatically → Cron triggers → Quartz builds → Site liveWhy scheduled publishing?
- Never forget to publish changes
- Consistent update schedule
- Hands-free operation
- Works while you’re away
Time to complete: 10-15 minutes
Prerequisites
Section titled “Prerequisites”Before setting up cron, you must have:
Required
Section titled “Required”- Alfred workflows set up and working
- Your
publish.shscript must be working
- Your
- Always-on Mac (Mac mini recommended)
- System Settings → Energy → Prevent sleeping: ON
- Executable script:
Terminal window chmod +x ~/Developer/mementropy-quartz/scripts/publish.sh
Verify Prerequisites
Section titled “Verify Prerequisites”Test that manual publishing works:
cd ~/Developer/mementropy-quartz && ./scripts/publish.shIf this fails, fix the publish script first before setting up cron.
Setup Instructions
Section titled “Setup Instructions”Step 1: Edit Your Crontab
Section titled “Step 1: Edit Your Crontab”crontab -eThis opens the cron editor (vim by default).
If you’ve never used vim:
- Press
ito enter INSERT mode - When done: Press
Esc, type:wq, press Enter to save
Step 2: Add Publish Jobs
Section titled “Step 2: Add Publish Jobs”Add these lines:
# Quartz automated publishing - 9 AM daily0 9 * * * cd $HOME/Developer/mementropy-quartz && ./scripts/publish.sh >> /tmp/quartz-publish.log 2>&1
# Quartz automated publishing - 6 PM daily0 18 * * * cd $HOME/Developer/mementropy-quartz && ./scripts/publish.sh >> /tmp/quartz-publish.log 2>&1What these lines do:
0 9 * * *- Run at 9:00 AM every day0 18 * * *- Run at 6:00 PM every daycd $HOME/Developer/mementropy-quartz- Change to your Quartz project./scripts/publish.sh- Run the publish script>> /tmp/quartz-publish.log 2>&1- Append output to log file
Step 3: Save and Verify
Section titled “Step 3: Save and Verify”Save (:wq in vim), then verify:
crontab -lYou should see your two entries.
Understanding Cron Time Format
Section titled “Understanding Cron Time Format”* * * * * command| | | | || | | | +--- Day of week (0-7, Sunday = 0 or 7)| | | +----- Month (1-12)| | +------- Day of month (1-31)| +--------- Hour (0-23)+----------- Minute (0-59)Common Schedules
Section titled “Common Schedules”| Pattern | Meaning |
|---|---|
0 9 * * * | Every day at 9 AM |
0 18 * * * | Every day at 6 PM |
0 9,18 * * * | Daily at 9 AM and 6 PM (single line) |
0 12 * * 1-5 | Weekdays at noon |
*/30 * * * * | Every 30 minutes |
Use crontab.guru to test expressions.
Testing Your Cron Jobs
Section titled “Testing Your Cron Jobs”Test 1: Manual Trigger
Section titled “Test 1: Manual Trigger”Create a test job that runs in 2 minutes:
- Check current time:
date - Edit crontab:
crontab -e - Add test job (adjust time to 2 minutes from now):
# TEST - Remove after verifying32 14 * * * cd $HOME/Developer/mementropy-quartz && ./scripts/publish.sh >> /tmp/quartz-test.log 2>&1
- Save and wait
- After 2 minutes:
cat /tmp/quartz-test.log - Remove test job
Test 2: Check Log After Real Run
Section titled “Test 2: Check Log After Real Run”After 9 AM or 6 PM:
tail -50 /tmp/quartz-publish.logExpected output:
- Build output from Quartz
- Git commit/push messages
- “Published successfully” or “No content changes”
Test 3: Verify Site Updated
Section titled “Test 3: Verify Site Updated”- Make a change to any content file
- Wait for next cron run
- Check site ~3 minutes after scheduled time
- Your change should be visible
Monitoring and Maintenance
Section titled “Monitoring and Maintenance”View Recent Publishes
Section titled “View Recent Publishes”# Last 50 linestail -50 /tmp/quartz-publish.log
# Today's entriesgrep "$(date +%Y-%m-%d)" /tmp/quartz-publish.log
# Count today's publishesgrep "$(date +%Y-%m-%d)" /tmp/quartz-publish.log | wc -lLog Rotation
Section titled “Log Rotation”Add to crontab to keep log manageable:
# Rotate log monthly (1st of month at midnight)0 0 1 * * tail -1000 /tmp/quartz-publish.log > /tmp/temp.log && mv /tmp/temp.log /tmp/quartz-publish.logTroubleshooting
Section titled “Troubleshooting”Cron Job Doesn’t Run
Section titled “Cron Job Doesn’t Run”Check cron is running:
ps aux | grep cronCheck script permissions:
ls -la ~/Developer/mementropy-quartz/scripts/publish.sh# Should show: -rwxr-xr-xTest script manually:
cd ~/Developer/mementropy-quartz && ./scripts/publish.shLog File Empty
Section titled “Log File Empty”Check paths:
crontab -l# Verify paths are correctGive cron Full Disk Access:
- System Settings → Privacy & Security → Full Disk Access
- Add
/usr/sbin/cron
Changes Don’t Appear
Section titled “Changes Don’t Appear”- Check cron ran:
grep "$(date +%Y-%m-%d)" /tmp/quartz-publish.log - Check for changes: Log shows “No content changes”?
- Check GitHub Actions: Visit repo Actions tab
- Wait for deployment: Takes 2-3 minutes after push
Disable Cron
Section titled “Disable Cron”Temporarily (comment out):
crontab -e# Add # at start of linesPermanently:
crontab -e# Delete the linesCombining Manual and Scheduled
Section titled “Combining Manual and Scheduled”Use both Alfred and cron together:
| Method | When to Use |
|---|---|
Alfred publish | Immediate publishing, testing |
| Cron | Regular automatic updates |
They use the same script, so they work seamlessly together.
Typical workflow:
- Write content throughout the day
- Use
previewto test locally - Either
publishimmediately or let cron handle it
Quick Reference
Section titled “Quick Reference”Cron Commands
Section titled “Cron Commands”crontab -l # List jobscrontab -e # Edit jobscrontab -r # Remove ALL jobs (careful!)Log Commands
Section titled “Log Commands”tail -f /tmp/quartz-publish.log # Watch livecat /tmp/quartz-publish.log # View allTest Expressions
Section titled “Test Expressions”Visit crontab.guru to test cron expressions.
Related
Section titled “Related”- Alfred Workflows for Quartz - Core workflow setup
- Remote Publishing - iPhone/iPad control
- Troubleshooting Guide - Debugging tips
Last updated: 2025-01-13