Theres no great answer. It depends to a certain extent on your requirements and hardware.
If you want the actual temperature value then
Its included in the output of prtdiag.
But thats not particularly convenient for scripting
Depending on hardware type using PICL might be more convenient.
On v210's etc the following
prtpicl -c temperature-sensor -v
produces something that would more amenable to scripting.
If you just want alerts, then the SC on some hardware eg v210's can be configured with high and low limits. Then you can set the SC variable sys_eventlevel=3 and those
alerts should appear in /var/adm/messages