0

I want to check the number of processess running and if this number of process is between 0-20 then print the number of process, if between 20-40 issue a warning and if between 40-70 issue a critical warning.

This code is being written to check the number of icinga processes.

This is the code I have so far to count the number of processes :

ps -ef | grep icinga | wc -l

From here on I do not understand how to give the above condition with a nested if else condition.

Aserre
  • 4,916
  • 5
  • 33
  • 56
JBOSSUSER
  • 35
  • 9
  • Does this answer your question? [How do I do if statement arithmetic in bash?](https://stackoverflow.com/questions/8304005/how-do-i-do-if-statement-arithmetic-in-bash) – Aserre Jan 20 '20 at 12:27

1 Answers1

0

number=$(ps -ef | grep icinga | wc -l)
if ((number >= 20 && number <= 40)); then
  # your code for warning
elif ((number > 40 && number <= 70)); then
  # your code for critical warning
fi

Id argue you wouldnt need the less than 70 part , as i imagine if it was 71 youd be really worried and the code wouldnt do anything :)

tomgalpin
  • 1,943
  • 1
  • 4
  • 12