Need to check the numeric value of command output be greater than or equal to some value


#1

Hello everybody,

I have a requirement to create a Inspec test to check the swap space of a linux system and pass if the swap space is greater than or equal to a certain value say 4GB. Is there an appropriate matcher for the command resource ?

describe command(‘free | grep ‘Swap’ | awk ‘{print ($2) }’)’) do
its(‘stdout’) { should “be greater than” 4000 }
end

Also Please let me know if there is any other way i can do this test.

Thanks


#2

Matchers:
https://www.inspec.io/docs/reference/matchers/

its(‘stdout’) { should be > 4000 }


#3

It looks like your “free” command should be “free -mt”. If you check for raw “free” output, that counts by bytes, not by Megabytes. I hope you caught this before you used your command, because it would report when you have less than 4000 bytes free, not 4 GB.