#!/bin/sh dbfile=/var/cache/stats.s3db sqlite3 $dbfile "INSERT INTO lastcpu(usage) VALUES($(awk '{print$3*100}' /proc/loadavg));" if [ $(sqlite3 $dbfile 'SELECT COUNT(*) FROM lastcpu;') -ge 4 ]; then query="INSERT INTO cpu24(usage) SELECT round(avg(usage)) FROM lastcpu;DELETE FROM lastcpu;" [ $(date +%d) -eq 1 ] && query="$query;DELETE FROM cpu;" [ $(date +%k) -eq 0 ] && query="$query;INSERT INTO cpu(usage) SELECT avg(usage) FROM cpu24; DELETE FROM cpu24;" sqlite3 $dbfile "$query" fi