awk problem

I am trying to use this awk command as filter:

 awk '/:Temperature/{printf "%s ", $2}' 

if I run it from bash, there is no error.
however if running from script, I get this error:

awk: syntax error near line 1
awk: illegal statement near line 1

the problem seems to be in space character after the %s
how to correct it?
thanks

---------- Post updated at 04:49 AM ---------- Previous update was at 04:35 AM ----------

solved, by using nawk and \

nawk '/:Temperature/{printf "%s\ ", $2}'

Your command lack an input (from a file or a pipe) otherwise, the BEGIN clause should be used.

I am curious to see how you ran your script from command line and what it does contain.

(also curious to see what was the input)

oh, ok.
that was a part of pipe.
input was from this command:

prtpicl -v -c temperature-sensor   

I couldn't use that other command for temperature, as it only displays ok/fail in Solaris10.
(hopefully) the output is CPU and server temperature. should be in Celsius?
the plan is to run it in cronjob once per day. so I will see if temperature rises suddenly. it will tell us if one of the CPU fans has failed.

the 3 wire fans are impossible to obtain. also Sun used to sell only heatsink+fans combo, which cost a lot. yes, it is small compared to the price of server, but buying anything is complicated here.

Could you show us how the result of
prtpicl -v -c temperature-sensor
look like ?

here it is:

  mb_p0_t_core (temperature-sensor, 760000072a)
  :_fru_parent   (760000062fH) 
  :Label         T_CORE 
  :HighPowerOffThreshold         100 
  :HighShutdownThreshold         93 
  :HighWarningThreshold  88 
  :Temperature   50 
  :_class        temperature-sensor 
  :name  mb_p0_t_core 
  mb_t_enc (temperature-sensor, 7600000732)
  :_fru_parent   (7600000611H) 
  :Label         T_ENC 
  :HighPowerOffThreshold         51 
  :HighShutdownThreshold         48 
  :HighWarningThreshold  40 
  :LowPowerOffThreshold  -6 
  :LowShutdownThreshold  -3 
  :LowWarningThreshold   5 
  :Temperature   28 
  :_class        temperature-sensor 
  :name  mb_t_enc 

edit:
btw, can someone help me with the script to compare the temperature with previous and output message if the difference is more than 3 deg?

Are you checking the temperature only once per day ?

yes, only once per day.
should we do it per hour?

This would require to be tested : unplug a fan and monitor the temperature to see how fast the temperature will increase.

Note that to secure the test, you must benchmark it under high CPU load condition to build the "worse case" possible and see the behaviour of temperature increase, you will then be able to determine what would be a reasonable check frequency to detect when the temperature increase too much.

(I would not be stonished if the temperature of a CPU whose fan is broken and under high load could increase to more than 80� in less than an hour.)

I see.
but could there be any problems running 'prtpicl' every hour? (because it accesses lowlevel hardware)

the server is not under heavy load.
I doubt both fans would fail at same time. and with just one fan, temperature is less than 60deg. (there is a bunch of those larger fans in case that help too)

It's up to you to make your own decision, depending on wether you estimates how critical and possible it is or not.

:slight_smile:

well after a day or so, there are no problems with the script.

/offtopic
it occurred to me that a simple solution would be to monitor the difference between two temperatures (CPU and case) at same instance of time. because the chassis temperature doesn't change if CPU fan stops working.