Cleaning Up Duplicate Cron Jobs on Asterisk Servers
The Problem
Over time, especially with configuration management tools (Ansible, Puppet) or manual administration, duplicate cron jobs accumulate. Common on PBX servers where monitoring scripts get added in multiple places.
Diagnosis
# List all cron sources
ls -la /etc/cron.d/
crontab -l 2>/dev/null
sudo crontab -l 2>/dev/null
# Check for duplicate script references
grep -r 'trunk-monitor\|pbx-backup\|asterisk' /etc/cron.d/
In our case, we found:
/etc/cron.d/pbx-monitoring -- the intended cron file (deployed by our script)
/etc/cron.d/asterisk-backup -- duplicate backup job (stale)
/etc/cron.d/asterisk-trunk-monitor -- duplicate trunk monitor running every MINUTE
The trunk monitor running every minute was generating unnecessary load and log noise.
Fix
# Remove duplicates, keep only the canonical cron file
sudo rm /etc/cron.d/asterisk-backup
sudo rm /etc/cron.d/asterisk-trunk-monitor
# Verify only the intended cron remains
ls /etc/cron.d/pbx-monitoring
cat /etc/cron.d/pbx-monitoring
Prevention
- Use a single cron file (e.g.,
/etc/cron.d/pbx-monitoring) for all PBX-related scheduled tasks - Include cron deployment in your deploy script so it is the single source of truth
- Add a step to your deploy script that removes known stale cron files:
# In deploy.sh
for stale in asterisk-backup asterisk-trunk-monitor; do
ssh_cmd "sudo rm -f /etc/cron.d/${stale}"
done
User Notes
No notes yet. Be the first to contribute a tip or example.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.