I want to have some condition, possible in new .sh and test if its ok or not.
For the start I want to tell temp is OK or not, just echo. Then i will figure out how to send to email.
I have something similar but for raspberry and mail function, but here on ubuntu i don't figure out just yet.
If all you're looking for is a way in Bash to test the value of a number, then the if statement can handle that on its own.
For example, here's a script that will test a previously-defined number, and display one message if it's less than or equal to 90 (the meaning of the -le arithmetic operator), and a different message if any other condition is met (i.e. if it's greater than 90):
Here's the output of a sample session:
So if all you're looking for is "If less than X do this, if greater than X do the other" the if statement is probably all you need. Hope this helps.
I'd just included that as a demonstration of how if works, really, so you could get an idea of what you need to do in your own code. So rather than directly using my example script, you'd adapt it and write your own if statement in your script to test the value of your temperature variable, after your script had set it.
So looking at your provided code, your could write an if statement at the end to test the value of the tc variable (assuming that's correct, and it does contain just a single integer that is the number you want to test). If the variable tc isnt' the right one then you'd use whatever variable contains the CPU temperature as an integer, and do the if tests on that.
If that doesn't work then if you can provide an example of the code you've written and what goes wrong when you run it, I'd be happy to help further in debugging and we can take things from there.
Aside from missing out the $ before your variable name as has been pointed out, the other problem you'll have here is that you have to cast your temperature variable (which is a floating-point number) into an integer. Bash built-in arithmetic of the kind we're using here solely works with integers, and not floats.
There are many ways you could do that - off the top of my head, you could get an external integer calculator (such as bc) to divide it by one, which will have the effect of trimming off the decimal part.
For example:
So here I start with a hard-coded floating point value for temperature, get bc running in its default integer-only mode to divide it by one, assign that result to a variable called integer, and do my Bash arithmetic operators on that integer.
People hello to everybody exist a way to do a script for view the temperature. I have
Red Hat Linux release 9 (Shrike)
Kernel 2.4.20-8 on an i686
THANk YOU FOR YOUR TIME. (4 Replies)
How to get a CPU temperature and current power consumption in T5220 server both from system controller and Operating system. I need details by cores. Thanks in advance. (13 Replies)
This is the code:
while test 1 -eq 1
do
read a
$a
if test $a = stop
then
break
fi
done
I read a command on every loop an execute it.
I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test.
For example echo hello.
Now the... (1 Reply)
Hi,
I just set up a raid Z array in solaris xpress and I notice that the drives feel pretty damn hot. I use speedfan to monitor the temperatures of the hard drives in XP. Is there a similar program for solrais? I assume there would be since the drives all have temp sensors in them, but I... (2 Replies)
Hi all
I have a SUN V480 server with 4 processores and I've noticed that the temperature for 2 of the 4 processers are quite high (63 degrees Celsius).
Does anyone know what the operating temperatures of the Sparc CPU's are? I'm not getting any warning messages yet, but I want to resolve the... (3 Replies)
Is there command in sco unixware 7.1.3 from which i can find the temperature of the system/hardware.
Something equivalent to prtdiag in solaris maybe
thanks (1 Reply)
I'm fairly new to hpux, so this is what i've been trying to figure out. Is it possible to get any logs on hpux that would indicate if the system, cpu, or other hardware components reached above normal or critical temperatures?
Thanks,
-K (0 Replies)