Bash, shell processing decimal

zhaozj2021-02-12  175

Today, I want to write a shell script, the purpose is to monitor Load Average, and restart RESIN when Load Average is higher than 7.5. It has been suspected that the version of the resin2. * Will cause Java to kill at high utilization. Therefore, the system is very unstable, but attempts to upgrade to RESIN3, it needs to change the Java code on the line, because RESIN3 is stricter for Java requirements. Many code is not strict. So the temporary alternative is to run the monitor for half an hour.

But when writing the monitor, I encountered the problem, shell handled the decimal number. My script is like this:

#! / bin / sh a = `uPtime | awk -f", "'{print $ 4}' | awk '{print $ 3}'` b = 7.50c = `expr $ a /> $ b`if [$ c -EQ 1] Then /usr/local/resin/bin/restart.sh echo `Date` >> /usr/local/resin/logs/monitor.logfi

This should be written at least to correctly express what I mean. But the problem is how I want to test the decisive and subtraction and subtraction of the decimal point when I write this code.

Bash-2.03 # EXPR 8.8 / 9.9EXPR: NON-NUMERIC ARGUMENT

Depressed, tomorrow again research! However, the size can be more than OK, others belong to amateur homework, huh, huh!

Subsequent: In fact, the shell could not handle the decimal. I now modify the script as follows, so as not to mislead everyone, I am really sorry:

#! / bin / sha = `uPtime | awk -f", "'{print $ 4}' | awk '{print $ 3}'` b = `Echo $ A | awk '$ 1> 9 {Printf ($ 1);} '`IF [" $ b "=" $ a "] THEN ... FI

转载请注明原文地址:https://www.9cbs.com/read-6522.html

New Post(0)