bashshellicinga

Bash Shell script to check how many processess are running and issue warning if exceeds 20?


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.


Solution

  • 
    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 :)