Script That Find Numbers Less Than 10

We have an existing script called "slots.sh" that prints a few numbers. I want to have another shell script that looks if there is any number from this output that is less than 10. If it does find a number that is less than 10, it then emails to me the output of "slot. sh", if it is equal to 10 or above, no email will be sent. Really appreciate any help.

What is your OS?

uname

Then, please give an example output from slots.sh (or slot.sh)!
And please wrap it in code tags for best readability.

Hello. :slight_smile:

OS is Linux (RHEL6)

slots.sh checks for job slots available.

OSREL | FREE (%) 
------+-------
   40 |      100
   50 |      100
   60 |      108
   70 |      9

With this example, under FREE column, RHEL 7 has only 9% free job slots. Thus, it then emails me for the output of slots.sh.

Try

./sloth.sh | tee TEMP |
{ read
  read
  while IFS="| " read OSREL FREE REST
    do  if [ "${FREE:-10}" -lt 10 ]
          then  mail user@domain <TEMP
                break
          fi
    done
}
rm TEMP
1 Like
grep -q " [0-9] *$" output_file && mail -s "slots.sh results" mail.recipient@somename.com < output_file

Thank you very much! This worked!

Another solution:

#!/bin/bash
temp=$(./sloth.sh)
if grep -q ' [0-9]$' <<< "$temp"
then
  mail user@domain <<< "$temp"
fi

(Just seeing that rdrtx1 in post#5 has the same idea with grep.)

Thank you everyone for the help. It;s working now. :slight_smile:

Moderator comments were removed during original forum migration.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.