Daily Server Health Report Cron: Email It Each Morning
Most server problems warn you first: disk space creeps up, memory runs low, a service stops after a reboot. But nobody logs in every day to check. A daily server health report cron fixes that by running a small script each morning and emailing you the result. This guide shows you how to build that cron job email report from scratch: a short bash script, a cron entry, and mail delivery that works on a typical VPS.
What the Daily Report Should Cover
A good report is short enough to read in two minutes and complete enough to catch the problems that actually take sites down. Keep it to six checks. First, uptime and load average, so you can see whether the server rebooted overnight and whether it is under strain. Second, disk space on every filesystem, because a full disk stops databases, logs, and uploads at once. Third, memory and swap use. Fourth, failed systemd services. Fifth, SSL certificate expiry for your main domains. Sixth, the newest lines from the web server error log.
You do not need a monitoring platform for any of this. The commands below are already on most Ubuntu and Debian servers, and the whole report fits in one plain-text email. If you want deeper live numbers during the day, our guide to monitor disk, RAM, and CPU usage with htop and Glances covers interactive tools for that job.
Write the Server Monitoring Script
Create the script at /usr/local/bin/health-report.sh. This server monitoring script prints one section at a time so the email is easy to scan, and it only reads state: it changes nothing.
#!/bin/bash
echo "== UPTIME AND LOAD =="
uptime
echo ""
echo "== DISK SPACE =="
df -h
echo ""
echo "== MEMORY =="
free -h
echo ""
echo "== FAILED SERVICES =="
systemctl --failed --no-pager
Make it executable and run it once by hand before you automate anything:
sudo chmod +x /usr/local/bin/health-report.sh
/usr/local/bin/health-report.sh
This first run is also your baseline. Note the normal load average, the normal free memory, and how full each disk is when things are healthy. Save that first output: a bash health check is most useful when you know what normal looks like on your own server.
Add SSL Expiry and Error Log Checks
Two more checks cover what visitors see: an expired certificate and a web server throwing errors. For certificate expiry, check the live certificate of your main domain with OpenSSL and print the expiry date:
echo ""
echo "== SSL CERTIFICATE EXPIRY =="
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
Replace example.com with your own domain and repeat the block for each domain you care about. If the notAfter date is less than a month away, renew that day.
For the error log, print just the last twenty lines:
echo ""
echo "== NGINX ERROR LOG (LAST 20 LINES) =="
tail -n 20 /var/log/nginx/error.log
If you run Apache instead, point the same command at /var/log/apache2/error.log. When the log lines show repeated 5xx errors, our guide on how to monitor Nginx error logs and get alerts on 5xx spikes explains how to dig into the cause.
Set Up Your Daily Server Health Report Cron
With the script tested, the next step is the schedule itself. This daily server health report cron runs at 07:00 every morning, pipes the script output into the mail command, and sends it to your inbox. Open your crontab with crontab -e and add this line:
0 7 * * * /usr/local/bin/health-report.sh | mail -s "Daily server health report - $(hostname)" [email protected]
Change [email protected] to your real address. On several servers, use the same time and let the subject line carry the hostname.
Two details matter here. First, cron runs with a minimal environment, so always use full paths in the script and in the crontab line. A command that works in your shell can fail under cron because its directory is not in the path. Second, keep a copy of the output on the server as well as in the email:
0 7 * * * /usr/local/bin/health-report.sh | tee -a /var/log/health-report.log | mail -s "Daily server health report - $(hostname)" [email protected]
If you prefer systemd timers to cron for scheduled work, see our guide to run scheduled tasks with systemd timers instead of cron. The script stays the same either way; only the scheduler changes.
Send the Report by Email
The crontab line assumes the server can send mail, which often needs work on a fresh VPS. The mail command needs a mail transfer agent behind it. The simplest setup is msmtp or ssmtp, which hand your mail to a real provider instead of trying to deliver it directly. Many VPS providers block outbound port 25, so sending direct from your VPS often fails or lands in spam. The fix is to relay through your mail provider on a submission port such as 587, with a username and password.
For an ssmtp mail setup, install the package and edit its config file:
sudo apt install ssmtp mailutils -y
sudo nano /etc/ssmtp/ssmtp.conf
Point it at your provider like this:
mailhub=smtp.example-mail.com:587
UseSTARTTLS=YES
[email protected]
AuthPass=your-app-password
FromLineOverride=YES
Use an app password from your mail provider if it offers one, rather than your main account password, and keep the config file readable only by root with sudo chmod 640 /etc/ssmtp/ssmtp.conf. Never paste a real password into a script or a shared file.
Send a test message before you rely on the setup. If it does not arrive, check the mail log at /var/log/mail.log and recheck the provider address, port, and login. Common causes are a wrong port, a missing app password, or a firewall rule blocking outbound port 587.
Test the Report Before You Trust It
Prove the whole chain works before you trust it. First, run the script by hand. Second, send a test mail with the same command cron will use:
/usr/local/bin/health-report.sh | mail -s "Test health report - $(hostname)" [email protected]
Third, force the cron entry to run once by changing its time to two minutes from now, waiting, and checking your inbox. Then change the time back to 07:00. If the test mail arrives but the cron mail does not, the problem is almost always the cron environment: a missing full path or a permission on the script.
Also test the failure cases on purpose. Stop a non-essential service for a minute and run the script to confirm it appears under failed services. These quick checks prove the report will actually warn you when something goes wrong, instead of quietly printing good news every morning. The next morning, the report should be waiting in your inbox without you doing anything.
Read the Report in Two Minutes Each Morning
The report only helps if reading it becomes a habit, so give it a fixed two-minute routine. Scan the load average first: it should stay below your CPU core count. Then check disk space, looking for any filesystem above 85 percent full. Then glance at memory, failed services, and the certificate date. Finally, read the last few error log lines. Most mornings every line will look normal, and that is the point: a quiet report means the server is fine, and you move on with your day.
When a line does look wrong, act on it the same morning. Free disk space before it hits 100 percent, restart a failed service and read its log, or renew a certificate with less than two weeks left. If you also want to know the moment your site stops answering, rather than waiting for the morning, our guide to monitor your website uptime for free with Uptime Kuma covers a live check that pages you right away.
Common Problems and Fixes
Most failures in this setup fall into four groups. If no mail arrives at all, check the mail log first, then confirm the relay settings and that outbound port 587 is open. If the mail arrives empty, the script probably printed an error to stderr instead of stdout, or a command inside it failed under cron: run the script by hand and read the output. If the mail arrives but a section is missing, that command may not exist on your server, so install the package that provides it or drop the section.
If the report arrives at the wrong time, remember that cron uses the server clock, which may be set to UTC while you think in local time. Check the time with date and either adjust the cron hour or set the server timezone with sudo timedatectl set-timezone Your/Zone. If the email lands in spam, send from an address on a domain you control with SPF and DKIM set up, instead of a generic address.