Last active
December 16, 2015 04:48
-
-
Save blackraccoon000/5379311 to your computer and use it in GitHub Desktop.
teratermマクロ
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
;==■ファイル名作成者名========================== | |
; Filename : sv.ttl | |
; Description : SSH Auto login | |
; Author : Yutaka | |
; Created : 2013/03/14 | |
; modified : | |
;============================================== | |
;==■参考URL===================================== | |
;-Tera Termマクロ-SSH自動ログイン | |
;http://www.j-oosk.com/teraterm/macro/204/ | |
;-SSH自動ログ取得マクロ | |
;http://www.j-oosk.com/teraterm/logging/579/ | |
;-teratermマクロ(おまけ) | |
;http://www.rose.sannet.ne.jp/nterasim/linux/teratermlogin.html | |
;-filestrseek | |
;http://teraterm-macro.seesaa.net/article/267935083.html | |
;-inputbox | |
;http://teraterm-macro.seesaa.net/article/106891883.html | |
;Japanized UTF-8 Tera Term Pro | |
;http://netguide.sakura.ne.jp/teraterm.html | |
;filereadln | |
;http://ttssh2.sourceforge.jp/manual/ja/macro/command/filereadln.html | |
;filestrseek | |
;http://ttssh2.sourceforge.jp/manual/ja/macro/command/filestrseek.html | |
;TELNET自動ログインマクロ | |
;http://www.j-oosk.com/teraterm/macro/150/ | |
;=============================================== | |
;==■接続先ホスト/ユーザ名/パスワード設定===== | |
HOSTADDR = '192.168.11.50' | |
USERNAME = 'rac' | |
PASSFILE = 'C:\teraterm\password.dat' | |
;=============================================== | |
;==■IPアドレス指定============================= | |
;inputbox 'Please input an IP address or the host name.' 'Host information input' | |
;HOSTADDR = inputstr | |
;strlen HOSTADDR | |
;if result=0 then | |
; messagebox 'Host information is not input.' 'Input error' | |
; end | |
;endif | |
;=============================================== | |
;==■パスワード指定============================= | |
;passwordbox 'パスワードを入力してください。' 'Please input a password.' | |
;PASSWORD = inputstr | |
;strcompare PASSWORD '' | |
;if result=0 then | |
; messagebox 'A password is not input.' 'Input error' | |
; end | |
;endif | |
;=============================================== | |
;==■暗号化ファイル:パスワード取得============== | |
;; パスワード取得 | |
getpassword PASSFILE USERNAME PASSWORD | |
;=============================================== | |
;==■ログGET_事前準備=========================== | |
;; ログ名の指定 | |
inputbox 'ログ名を指定' 'Host information input' | |
LOG_PURPOSE = inputstr | |
;; ログ保存場所指定 | |
LOG_PATH = 'C:\logs' | |
;; ログファイル保存フォルダの設定 | |
LOG_FILE = LOG_PATH | |
;; ログ保存フォルダの存在確認(無ければ作成:作成失敗は終了) | |
foldersearch LOG_FILE | |
if result = 0 then | |
foldercreate LOG_FILE | |
if result <> 0 then | |
messagebox 'A folder could not be made.' 'Making error' | |
end | |
endif | |
endif | |
;; パス修正 | |
strconcat LOG_FILE '\' | |
;; ログファイル名の設定 | |
getdate LOG_NAME '_%Y%m%d_%H%M%S_' | |
strconcat LOG_FILE LOG_PURPOSE | |
strconcat LOG_FILE LOG_NAME | |
strconcat LOG_FILE HOSTADDR | |
strconcat LOG_FILE '.log' | |
;messagebox LOG_FILE 'LOG_FILENAME' | |
;=============================================== | |
;==■SSHログインコマンド組み立て================ | |
;; コマンド組立て | |
COMMAND = HOSTADDR | |
strconcat COMMAND ':22 /ssh /2 /auth=password /user=' | |
strconcat COMMAND USERNAME | |
strconcat COMMAND ' /passwd=' | |
strconcat COMMAND PASSWORD | |
;=============================================== | |
;==■接続と判定================================= | |
;; 接続 | |
connect COMMAND | |
settitle "SV-RAC" | |
;; 接続判定1(接続出来ない場合はメッセージを表示しマクロ終了) | |
if result <> 2 then | |
messagebox 'It could not be connected.' 'Connection Error' | |
end | |
endif | |
;; 接続判定2(接続して10秒以内にプロンプトが表示されない場合もマクロ終了) | |
timeout = 10 | |
wait '>' '$' '#' | |
if result = 0 then | |
end | |
endif | |
;=============================================== | |
;==■ログ取得開始================================ | |
logopen LOG_FILE 0 0 | |
logwrite '*********************************'#13#10 | |
logwrite 'ホストIP ADDRESS : '#13#10 | |
logwrite HOSTADDR | |
logwrite #13#10 | |
logwrite #13#10'*********************************'#13#10 | |
;==必ず打つコマンド============================ | |
sendln 'hostname' | |
wait '>' '$' '#' | |
;; ホスト名表示 | |
sendln 'date' | |
wait '>' '$' '# | |
;==■log停止================================== | |
logclose | |
;============================================= | |
;==■File検索================================== | |
fileopen filehandle LOG_FILE 0 | |
;fileが開くかチェック | |
if filehandle = -1 then | |
messagebox 'file open error' 'end' | |
fileclose fhandle | |
endif | |
;:loop_seek | |
;;ファイル "teraterm.log" から文字列 "hostname" を検索 | |
filestrseek filehandle 'hostname' ;検索文字列を入れる | |
;messagebox result '結果' | |
;;文字列があった場合の分岐 | |
if result= 1 then | |
; messagebox 'あるよ!' 'end' | |
goto on_set | |
endif | |
;;文字列がない場合の分岐 | |
if result= 0 then | |
; messagebox 'ないよ!' 'end' | |
goto no_set | |
endif | |
;; 読み込んだ行を表示 | |
;filereadln filehandle str | |
;messagebox str '読み込んだ行を表示' ;test echo | |
;goto loop_seek | |
;=============================================== | |
;==■ログ取得再開================================ | |
:no_set | |
:on_set | |
fileclose filehandle | |
logopen LOG_FILE 0 1 | |
;=============================================== | |
;==■任意コマンド================================ | |
;statusbox 'statusbox' 'test' | |
;; コマンド入力 | |
;sendln 'ifconfig -a' | |
;wait '>' '$' '# | |
;sendln 'echo $LANG' | |
;wait '>' '$' '# | |
;sendln 'chkconfig --list sshd' | |
;wait '>' '$' '# | |
;sendln 'exit' | |
;==マクロ終了================================== | |
wait '>' '$' '#' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment