Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Sun Solaris Unix Shell script that adds 2 to a string numeric and checks last value for change before emailing

Currently our Sun E450 could detect room temperature (from "prtdiag -v" and I've
observed that it's consistently reporting about 1.5-2.0 Celsius lower than the
general DC room temperature :

# prtdiag -v | grep -i ambie
AMBIENT    19

"date" command in this Solaris box's format is :
# date
Sat May  9 06:06:58 SGT 2009


I'll need a Shell script that run every 1 minute (I'll put this into the crontab as
1,2,...59 * * * * /path/script_name) that will do the following :

I'll need this Shell script to be able to notify/email me when room temperature
(>= 21  AND there's a change from the last value)   or
(<= 20  AND the temperature recorded one minute ago is >= 21)

Above script basically notifies me once only (not repeatedly) when temperature
hits 21 C  but if temperature keep going up (at levels above 21 C) it will keep emailing/
notifying me.
This script only notify me once when temperature go below 21 C (but only notify
once and not repeatedly and it will stop notifying if room temperature stays below
20 C)  as the pseudo codes below describe :

Currentdatetime=yyyymmdd:hhmm   (24 hr format)
echo RoomTemp + " " + Currentdatetime  >> yyyymmdd_outputfile
add 2 to the value given by "prtdiag -v | grep AMBIENT" (call this variable RoomTemp
  if RoomTemp equals or exceeds 21
    check RoomTemp vs last_temperature recorded in last line of yyyymmdd_outputfile
        if RoomTemp equal or exceed 21 AND is higher than last_temperature
           email to myemail the value Currentdatetime+" "+":Room temp is now "+RoomTemp
        endif
  if last_temperature in last line of yyyymmdd_outputfile >= 21 and RoomTemp is <=20
    email to myemail the value Currentdatetime+" "+":Room temp now is down to "+RoomTemp
  endif
exit

ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial