標準出力に書き出すだけなので、crontab で適当なログファイルに追記するようにリダイレクトするがよろし。
エラー時は non-zero で終了するので cronlog とかで監視もできる。
Last active
December 20, 2015 16:48
-
-
Save yuya-takeyama/6163654 to your computer and use it in GitHub Desktop.
ネットワークルーター YAMAHA RTX1200 の温度をログに残すヤツ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'open-uri' | |
require 'time' | |
HOST = "HOST_NAME" | |
OPEN_OPTS = {http_basic_authentication: ["BASIC_AUTH_USER", "BASIC_AUTH_PASSWORD"]} | |
if open("http://#{HOST}/admin/", OPEN_OPTS).find {|line| line.force_encoding("Shift_JIS").encode!("UTF-8") =~ /^(\d+)℃/ } | |
puts "%s\tOK\t%d" % [DateTime.now, $1.to_i] | |
else | |
puts "%s\tNG" % [DateTime.now] | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment