Sample Header Ad - 728x90

Script to send an alert mail once the disk space is above 90% sends disk full even when the disk isn't full, how to resolve this issue?

0 votes
1 answer
304 views
#!/bin/bash df -m > myfile server_ip_address=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) if awk '$2 > 10000 && $5 > 90' myfile ; then echo "Disk Full in $server_ip_address" else echo "Nothing wrong with the server" fi When I execute the script, always get disk full as output? Output of df -m looks like this: Filesystem 1M-blocks Used Available Use% Mounted on /dev/mapper/centos-root 949305 512827 436479 55% / devtmpfs 3811 0 3811 0% /dev tmpfs 3823 0 3823 0% /dev/abc tmpfs 3823 18 3806 1% /run tmpfs 3823 0 3823 0% /sys/fs/cgroup /dev/sda2 1014 175 840 18% /boot /dev/sda1 1022 12 1011 2% /boot/efi tmpfs 765 0 765 0% /run/user/2000 The outut of df -m differs from server to server. I am thus comparing if Size>10GB and Use%>90%. As some disk with size<10GB may not be important to be under 90% disk usage. **Update 1:** GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) OS is centos 7 Problem with the current code: I need to compare from the second row to last row columns, but my current code is comparing the first rows columns, that's why I suppose it's not working. How to resolve the issue?
Asked by achhainsan (543 rep)
Aug 6, 2023, 05:32 AM
Last activity: Aug 6, 2023, 01:30 PM