Log and disk monitor with cron
The script every ops team has: check the disk and the app's errors, raise an ALERT, and run it every 5 minutes with cron.
You'll end with: A tested monitoring script and its cron schedule in your GitHub, with a green pipeline.
Do it here, in your browser
Follow the steps on the left and type in the terminal on the right. Each step ticks itself off when your files are right. At the end, one button creates the repository in your GitHub with your work, and you get a ready LinkedIn post.
Or do it on your own computer
Prefer a real terminal? Make your copy from our GitHub template, work in Codespaces or on your machine, then submit the link below.
akopslabs/build-log-monitorSteps on your own computer
- 1
Make your copy
Press Use the GitHub template, keep the repository Public and create it.
- 2
Open a terminal
Code → Codespaces → Create codespace, or clone it on your own Linux or Mac machine.
- 3
Finish monitor.sh
Fill in DISK_USED, ERRORS, the status line and the ALERT. Keep the two settings lines at the top.
DISK_USED=$(df --output=pcent / | tail -1 | tr -dc '0-9') ERRORS=$(grep -c ERROR "$LOG_FILE" || true)
- 4
Schedule it
Create crontab.txt with a line that runs the script every 5 minutes.
*/5 * * * * cd ~/log-monitor && ./monitor.sh >> monitor.log 2>&1
- 5
Test and push
Run the check, then commit and push. Wait for AkOps check to go green.
chmod +x monitor.sh bash tests/check.sh git add . && git commit -m "Log and disk monitor" && git push
- 6
Submit and share
Paste your repository link below and press Check my project.