Brief-Wishbone9091
Member
Code:
#!/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:
Code:
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?
Last edited: