T
T
Tech2021-07-11 14:10:17
linux
Tech, 2021-07-11 14:10:17

How to compare values ​​in output lines and conditionally execute a script?

I display the temperature values ​​​​of the processor with the command:
sensors | grep "Core *" | awk '{print int($3)}'
At the output:

37
39
38
36

How to compare them with the value "60" and if at least one value is greater than 60, then execute a certain sh-script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-07-11
@bioid

For example, so

sensors | grep "Core *" | awk '{print int($3)}' | xargs -L 1 -i bash -c "[ {} -gt 37 ] && echo '{} больше 37'"

And with the script call it will be like this
sensors | grep "Core *" | awk '{print int($3)}' | xargs -L 1 -i bash -c "[ {} -gt 60 ] && ./too_hot.sh'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question