Web Hosting & VPS Tips

Unleash Your Server Potential with Expert Insights

Hosting provided by: Cloudways
Free to Try! Up to 40% Off!

Category: VPS Setup

Monitor UFW with a Bash script on Ubuntu—install UFW with
apt install ufw
then create /usr/local/bin/ufw-status sh with
nano /usr/local/bin/ufw-status.sh
:
#!/bin/bash\necho \"UFW Status - $(date)\"\nufw status verbose >> /var/log/ufw-status.log\necho \"Blocked packets:\" >> /var/log/ufw-status.log\ngrep \"BLOCK\" /var/log/ufw.log | tail -n 5 >> /var/log/ufw-status.log
Make executable with
chmod +x /usr/local/bin/ufw-status.sh
run hourly via cron with
echo \"0 * * * * root /usr/local/bin/ufw-status.sh\" >> /etc/crontab
On DigitalOcean check /var/log/ufw-status log—this tracks SSH and MySQL security ensuring uptime with automated logs

Back to All Tips