I'm a newbie at bash scripting and I'm trying to write a script that if the memory utilization is greater than 80% it will display a message.
Here's the code:
#!/bin/sh
ramusage=$(free | awk '/Mem/{printf("RAM Usage: %.2f\n"), $3/$2*100}'| awk '{print $3}')
if [ $ramusage -gt 80 ]; then
echo "Danger! Memory usage is $ramusage = critical"
else
echo "Chill.. Ram usage is $ramusage = normal"
fi
Unfortunately, after running the script I encountered the following error:
line 5: [: 15.95: integer expression expected
At this point, I'm not sure if my script is running correctly or what the error means. Any help would be appreciated.