;TeratermMacroによりSSHログイン! 
;初回のみ手入力でPassword入力を求められ暗号化で保存される仕組み
;IPアドレス192.168.0.1のLinuxサーバにUser1で入り、
;TOPコマンドを15秒おきに1時間結果ととってくる
;プログラムや取得ログはデスクトップのsshloginというフォルダへ。
;途中の”;messagebox”はプログラムの変数確認用です。
; ";"を外すとポップアップになるので不具合切り分け用です。
;起動は昼間ならダブルクリックで手動起動とか
;夜中とかちょうどのタイミングで始めたい人はタスクスケジューラ+MS-DOSで
;(↑タスクスケジューラで .ttl ファイルを直接指定できないので.ttl を起動するバッチを作って)
; 次の記事でその超シンプルなバッチをご紹介。
=============================================
この下から全部テキストエディタにコピペして拡張子 ” .ttl ” で保存 (例:ssh-login.ttl)


username = 'user1'
hostaddr = '192.168.0.1'
passwdfile = 'passwd-ssh.dat'
portnum = '22'

getenv 'USERPROFILE' DesktopPath

;messagebox DesktopPath 'sshlogin'


strconcat DesktopPath '¥Desktop¥sshlogin¥'
PASSPATH = DesktopPath
strconcat PASSPATH 'passwd-ssh.dat'

;messagebox PASSPATH 'test2'

LOGFULLPATH = DesktopPath
;strconcat LOGFULLPATH "¥Desktop¥sshlogin¥"

;messagebox LOGFULLPATH 'test3'

getpassword PASSPATH hostaddr PASSWORD

strspecial PASSWORD2 PASSWORD


dore = hostaddr
strconcat dore ':'
strconcat dore portnum
strconcat dore ' /ssh /auth=password /user='
strconcat dore username
strconcat dore ' /passwd="'
strconcat dore PASSWORD
strconcat dore '"'

;messagebox dore 'test4'

connect dore

;;ログインするだけなら、ここまででOKです

pause 5
getenv 'USERPROFILE' DesktopPath2
strconcat DesktopPath2 '¥Desktop¥sshlogin¥LOG¥'
changedir DesktopPath2
;messagebox DesktopPath2 'test5'

;; [ssh-login-top.logというファイル名で結果を保存]
logopen 'sshlogin-top.log' 0 0

 
;; [コマンド実行ループ]
;; ※変数iで実行回数を指定。
;; 15秒おきにコマンド打つので、1分なら5、1時間なら241かな?
;; 例えば12時0分0秒に始まって1時0分0秒に終わるなら241かな
;; "pause 1" + "pause 14" で1回の実行時間が15秒

i = 241
while i>0

sendln 'top'
pause 1
sendln 'q'
sendln
pause 14

i = i - 1
endwhile
end



logclose

closett

(2022年01月、円マークがバックスラッシュに見えてしまっているのを修正しました)