Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289
Original Poster
Rep:
Okay, I think I figured out what's going on. The output of $CPUTEST is visually a number, but is not classified in computation as a number. So the test -ge function does not handle it correctly like the = sign would, because test is (if I am correct) only for numeric and not for alpha-numeric much like the = sign would be.
This means, I need another way to do this other then -ge, or change the output of $CPUTEST to a numeric form of which, test can handle. Well, I have been working on this for 6 hours. I'm tired. Taking a nap.
OK. I think I've got it. Take this example script, checking the CPU use of klogd.
#!/bin/sh
xKLOGUSE=`ps aux | grep klogd | head -1 | awk -F" " '{print $3}'`
KLOGUSE=`echo $xKLOGUSE | awk -F. '{print $1}'`
echo $KLOGUSE
echo "----spacer line----"
if [ "$KLOGUSE" -gt 10 ]
then
echo "greater than"
else
echo "less than"
fi
echo "--done--"
The first awk statement strips out the CPU use value (sitting at 0.0 almost always on this bit.) The second awk removes the .0 from the end, losing a bit of accuracy, but that can be adjusted. note: Bash seems to like whole number integers, and treat floating point (decimal) numbers as strings.
Now that $KLOGUSE is an integer, the comparison works. You could put that second awk statement on the same line as the first, just piped over from the first awk. Either way.
If you NEED the accuracy of XX.X% instead of XX%, you could just strip out the decimal point and think of 0-999 instead of 0.0-99.0
Lemmie know if this fixes it, though you've probably already figured it out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.