Sponsored Content
Full Discussion: Test temperature and alert
Top Forums Shell Programming and Scripting Test temperature and alert Post 303023763 by drysdalk on Friday 21st of September 2018 07:39:18 PM
Old 09-21-2018
Hi,

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:

Code:
#!/bin/bash

temperature=44.55
integer=`echo "$temperature / 1" | /usr/bin/bc`

echo "Before conversion: $temperature"
echo "After conversion: $integer"

if [ "$integer" -le "90" ]
then
        echo "Less than 90, so that's OK"
        exit 0
else
        echo "Oh no, it's at least 90 !"
        exit 1
fi

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.

Here's an example session.

Code:
$ ./example.sh 
Before conversion: 44.55
After conversion: 44
Less than 90, so that's OK
$

Hope this helps.
 

9 More Discussions You Might Find Interesting

1. HP-UX

temperature records

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)
Discussion started by: uzerx
0 Replies

2. SCO

temperature monitor

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)
Discussion started by: gsb81
1 Replies

3. Solaris

CPU temperature

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)
Discussion started by: soliberus
3 Replies

4. Filesystems, Disks and Memory

Hard Drive Temperature?

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)
Discussion started by: ciscocbee
2 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

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)
Discussion started by: Max89
1 Replies

6. Solaris

CPU Temperature Details

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)
Discussion started by: fugitive
13 Replies

7. UNIX for Dummies Questions & Answers

MAKING A SCRIPT FOR TEMPERATURE

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)
Discussion started by: enkei17
4 Replies

8. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

9. Solaris

reading temperature again and ipmitool

some say '/usr/sfw/bin/ipmitool' can be used to read temperature. has anyone tried it? what options should be used? (1 Reply)
Discussion started by: orange47
1 Replies
Tcl_PrintDouble(3)					      Tcl Library Procedures						Tcl_PrintDouble(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_PrintDouble - Convert floating value to string SYNOPSIS
#include <tcl.h> Tcl_PrintDouble(interp, value, dst) ARGUMENTS
Tcl_Interp *interp (in) Before Tcl 8.0, the tcl_precision variable in this interpreter controlled the conversion. As of Tcl 8.0, this argument is ignored and the conversion is controlled by the tcl_precision variable that is now shared by all interpreters. double value (in) Floating-point value to be converted. char *dst (out) Where to store the string representing value. Must have at least TCL_DOUBLE_SPACE characters of storage. _________________________________________________________________ DESCRIPTION
Tcl_PrintDouble generates a string that represents the value of value and stores it in memory at the location given by dst. It uses %g format to generate the string, with one special twist: the string is guaranteed to contain either a "." or an "e" so that it does not look like an integer. Where %g would generate an integer with no decimal point, Tcl_PrintDouble adds ".0". | If the tcl_precision value is non-zero, the result will have precisely that many digits of significance. If the value is zero (the | default), the result will have the fewest digits needed to represent the number in such a way that Tcl_NewDoubleObj will generate the same | number when presented with the given string. IEEE semantics of rounding to even apply to the conversion. KEYWORDS
conversion, double-precision, floating-point, string Tcl 8.0 Tcl_PrintDouble(3)
All times are GMT -4. The time now is 01:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy