- In DevOps and Middleware environments, automation isn't complete until it's scheduled.
- Here, we master cron, at, @reboot, and Jenkins integration — running scripts automatically for backups, restarts, monitoring, and cleanups.
📑 Table of Contents
- 1️⃣ Automating with Cron
- 2️⃣ One-Time Tasks with At
- 3️⃣ Auto-Execute on System Reboot
- 4️⃣ Jenkins Scheduler Integration
- 5️⃣ Real Middleware Automation Examples
- 6️⃣ Tips & Troubleshooting
- 🏁 Summary
⏰ 1️⃣ Automating with Cron
- cron executes scripts periodically.
- Perfect for recurring jobs like backups, cleanup, and health checks.
Example 1: Daily Jenkins Backup at 3 AM
0 3 * * * /opt/scripts/jenkins_backup.sh >> /var/log/jenkins_backup.log 2>&1
[03:03] ✅ Jenkins backup completed
Example 2: Weekly Tomcat Log Cleanup
0 2 * * 0 /opt/scripts/cleanup_tomcat_logs.sh >> /var/log/tomcat_cleanup.log 2>&1
✅ Weekly cleanup done
🕐 2️⃣ One-Time Tasks with At
at executes a job once — ideal for maintenance windows, patches, or urgent restarts.
Example 3: Restart WebSphere at 11:30 PM
echo "/opt/IBM/WebSphere/AppServer/bin/stopServer.sh server1 && sleep 15 && /opt/IBM/WebSphere/AppServer/bin/startServer.sh server1" | at 23:30
Example 4: Run Backup Once in 2 Hours
echo "/opt/scripts/backup_db.sh" | at now + 2 hours
🔄 3️⃣ Auto-Execute on System Reboot
The @reboot keyword in crontab ensures your scripts run every time Linux boots.
Perfect for restarting services, mounting drives, or initializing environments.
Example 5: Auto-Start Tomcat After Reboot
@reboot /opt/tomcat/bin/startup.sh >> /var/log/tomcat_reboot.log 2>&1
Example 6: Health Check Script at Boot
@reboot /opt/scripts/health_check.sh >> /var/log/health_boot.log 2>&1
✅ All services active.
grep CRON /var/log/syslog after restart.⚙️ 4️⃣ Jenkins Scheduler Integration
In CI/CD, Jenkins provides cron-like scheduling for build pipelines.
Example 7: Daily Jenkins Build at 2 AM
pipeline {
triggers { cron('H 2 * * *') }
stages {
stage('Nightly Build') {
steps {
sh '/opt/scripts/build_app.sh'
}
}
}
}
Build completed successfully.
🧰 5️⃣ Real Middleware & DevOps Automation Examples
Example 8: NGINX Health Monitor Every 10 Minutes
*/10 * * * * /opt/scripts/nginx_health.sh >> /var/log/nginx_monitor.log 2>&1
[02:50] 🚨 NGINX down – restarted automatically.
Example 9: Database Backup Every 6 Hours
0 */6 * * * mysqldump -u root -pSecret middlewaredb > /backup/db_$(date +%F_%H).sql
Example 10: Restart Jenkins After Crash Detection
*/15 * * * * pgrep jenkins >/dev/null || systemctl restart jenkins
Example 11: Auto-Remount Missing Volume
@reboot mount | grep /mnt/backup >/dev/null || mount /dev/sdb1 /mnt/backup
🧠 6️⃣ Tips & Troubleshooting
- 📄 Check logs →
grep CRON /var/log/syslog - 🔒 Ensure permissions →
chmod +x /opt/scripts/*.sh - ⚙️ Test reboot jobs manually →
sudo run-parts /etc/cron.d/ - 📧 Use
MAILTOin crontab for notifications - 🚨 For Jenkins jobs, check
/var/lib/jenkins/jobs/*/builds
🏁 Summary
- Cron → Schedules recurring jobs
- At → Runs one-time tasks
- @reboot → Executes scripts on startup
- Jenkins → Manages enterprise-level schedules
- 💡 Combine them to create self-healing, auto-starting Middleware environments.