Last active
July 23, 2024 15:19
-
-
Save fenrir-naru/86d60962e7b4e6463cf82f7e9dacf14f to your computer and use it in GitHub Desktop.
HDL-AAX shutdown script
This file contains 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
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
# 設定内容 | |
url = "http://192.168.1.XXX" # TODO | |
password = "password" # TODO | |
module Kernel # required for version below 2.6 | |
def then | |
return to_enum(__method__) { 1 } unless block_given? | |
yield self | |
end unless method_defined? :then | |
end | |
# 以下処理内容 | |
require 'mechanize' | |
agent = Mechanize.new | |
# ログイン | |
agent.get(url).then{|page| | |
form = page.form_with(:name => 'form') | |
form.field_with(:type => 'password').value = password | |
button = form.button_with(name: 'login') | |
agent.submit(form, button) | |
} | |
agent.get(url + "/admin/system/power/shutdown").then{|page| | |
# シャットダウンページ | |
form = page.form_with(:name => 'form') | |
button = form.button_with(name: 'shutdown') | |
agent.submit(form, button) | |
}.then{|page| | |
# 確認画面 | |
form = page.form_with(:name => 'form') | |
button = form.button_with(name: 'execute') | |
agent.submit(form, button) rescue nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment