18

I want to display server load, disk space, usage and memory usage in bash script.

But when I try

echo "Memory usage:"
memory_usage=$ free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
echo $memory_usage

this and run the script using ./test.sh it gives me the error:

free command not found

5
  • what do you get if you say which free? Commented Apr 20, 2016 at 7:52
  • 2
    To store the output of a command, say var=$(command). Your var=$ command is wrong - note the space and the lack of parentheses around the command. Commented Apr 20, 2016 at 7:54
  • when I run script using git bash at that time I run free than also gives me error that free command not found Commented Apr 20, 2016 at 7:54
  • memory_usage=$(free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') this is also give same error. Commented Apr 20, 2016 at 7:55
  • 2
    Well this clearly means that you don't have the free package installed. Check How to add more commands to Git Bash Shell. Commented Apr 20, 2016 at 7:57

1 Answer 1

26

for debian /ubuntu . just run

apt-get install procps 

for centos

yum install procps

the procps include free , top etc linux base commond

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.