#!/usr/bin/csi -script (require-extension irregex) (use posix) (define ssh-host "dreamhost") (define previous-temperature-file "/tmp/.prev_temp") (define remote-message-location (string-append "/home/natsen1/multiagentsystems/servers/plots/data/" (get-host-name) ".msg" ) ) (define temperature-regex (string->sre "[0-9]+\\.[0-9]+")) (define get-current-temperature (lambda () (let ( ( temperature (irregex-extract temperature-regex (call-with-input-pipe "acpi -t" read-all) ) ) ) (if (null? temperature) #f (car temperature) ) ) ) ) (define get-current-time (lambda () (let ((result (call-with-input-pipe "date -u +\"%H\"" read-all))) (substring result 0 (- (string-length result) 1)) ) ) ) (define send-new-temperature (lambda (time temp) (system (string-append "ssh " ssh-host " \"echo " time " " temp " > " remote-message-location "\"" ) ) ) ) (define update-temperature-file (lambda (time temp) (with-output-to-file previous-temperature-file (lambda () (print time " " temp) ) ) ) ) (define update-temperature (lambda (time temp) (begin (update-temperature-file time temp) (send-new-temperature time temp) (print time " " temp) ) ) ) (define should-update-temperature? (lambda (previous-temperature-file current-time current-temp) (let* ( (temp-file-data (string-split (read-all previous-temperature-file) " ") ) (temp-file-time (car temp-file-data)) (temp-file-temp (cadr temp-file-data)) ) (not (and (string=? temp-file-time current-time) (string>=? temp-file-temp current-temp) ) ) ) ) ) (define report-temperature (lambda () (let ( (current-time (get-current-time)) (current-temp (get-current-temperature)) ) (if (file-exists? previous-temperature-file) (if (should-update-temperature? previous-temperature-file current-time current-temp ) (update-temperature current-time current-temp) (quote ()) ) (update-temperature current-time current-temp) ) ) ) ) (report-temperature)