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 PBXPrivate Branch Exchange, a private telephone switch. Asterisk is a software PBX that routes calls between internal extensions and the outside world. 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 trunkA connection between Asterisk and another PBX or an ITSP/carrier, used to send and receive external calls. 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
Know a tip or gotcha for this topic? Share it below and help others.
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.