I have the following tcl script:
#!/usr/bin/env tclsh
### Improvements
# Get database from conf-file
package require sqlite3
proc getCPUTemp {} {
if {1 != [regexp -all -line {^CPU_TEMP: +\+([0-9.]+)°C } [exec
sensors] -> temp]} {
error {Did not get exactly a single temperature line from [exec
sensors] output}
}
return ${temp}
}
proc storeCPUTemp {} {
storeMessage cpu-temp [getCPUTemp]
}
proc storeMessage {type message} {
db eval "
INSERT INTO messages
(type, message)
VALUES
(:type, :message)
"
}
proc storeSwap {} {
storeMessage swap-usage [exec swapon --noheadings --show]
}
if {$argc != 1} {
error "Error: ${argv0} DATABASE"
}
sqlite db [lindex $argv 0]
db timeout 10000
while {true} {
after [expr {1000 * (60 - [clock seconds] % 60)}]
set currentMinute [clock format [clock seconds] -format %M]
db transaction {
storeCPUTemp
# At the whole hour we save swap usage
if {${currentMinute} == "00"} {
storeSwap
}
}
}
# Not really necessary because the above loop never ends
# But I find this more clear and is robuster against change
db close
If I enter:
SELECT date
, message
, TYPEOF(message)
FROM messages
WHERE type = 'cpu-temp'
AND date = '2017-12-06'
I see that the temperature is saved as text.
In the past I had a script like this in Python who would save the
temperature as real. What do I need to change to let this script save it as
real also?
--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users