TeraTermのマクロを試してみる
TeraTermのマクロを試してみる。
VagrantでCentOSのサーバーを用意し、
IPアドレスを「192.168.33.10」にした状態。
とりあえずHello, world!を表示させてみる
下記のttlファイルを作成する。
;サーバーに接続 connect '192.168.33.10:22 /ssh /auth=password /user=vagrant /passwd=vagrant' ;プロンプトを待つ wait '[vagrant@vagrant-centos64 ~]$' ;「Hello, world!」を表示 sendln 'echo Hello, world!'
ttlファイルはTeraTermに関連付けられており、
ダブルクリックで実行すると、Hello, world!が表示される。
[vagrant@vagrant-centos64 ~]$ echo Hello, world! Hello, world!
waitregexを使うと正規表現指定で待つことができる
;サーバーに接続 connect '192.168.33.10:22 /ssh /auth=password /user=vagrant /passwd=vagrant' ;プロンプトを待つ waitregex '\[vagrant@.*\]\$' ;「Hello, world!」を表示 sendln 'echo Hello, world!'
変数を使ってみる
;接続情報 hostname = '192.168.33.10' port = 22 username = 'vagrant' password = 'vagrant' wait_str = '\[vagrant@.*\]\$' ;サーバーに接続 cmd = hostname strconcat cmd ':' strconcat cmd port strconcat cmd ' /ssh /auth=password /user=' strconcat cmd username strconcat cmd ' /passwd=' strconcat cmd password connect cmd ;プロンプトを待つ waitregex wait_str ;「Hello, world!」を表示 sendln 'echo Hello, world!'
パスワードを入力できるようにしてみる
;接続情報 hostname = '192.168.33.10' port = '22' username = 'vagrant' wait_str = '\[vagrant@.*\]\$' ;パスワード入力 passwordbox 'パスワードを入力してくだささい。' 'パスワード入力ダイアログ' password = inputstr strcompare password '' if result=0 then messagebox 'パスワードを入力してください。' 'エラー' end endif ;サーバーに接続 cmd = hostname strconcat cmd ':' strconcat cmd port strconcat cmd ' /ssh /auth=password /user=' strconcat cmd username strconcat cmd ' /passwd=' strconcat cmd password connect cmd ;プロンプトを待つ waitregex wait_str ;「Hello, world!」を表示 sendln 'echo Hello, world!'