目次
何をするか
TeraTermマクロによるSSHログイン、
コマンドの実行を実現する
事前準備
以下のパスに下記2つのテキストを準備する。
C:\Users\user1\Desktop\TTL\
・host_list.txt
・ホスト名.txt(例:SW1.txt)
host_list.txt
処理対象のホストのIPアドレスが記載されたテキスト
1 2 3 |
192.168.1.1 172.16.1.1 10.1.1.1 |
ホスト名.txt(例:SW1.txt)
ホストごとにホスト名.txtを用意
1 2 3 4 |
version 12.4 hostname Router no ip routing no ip cef |
コード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
hostlist = 'C:\Users\user1\Desktop\TTL\host_list.txt' separator = ',' commandlist_path = 'C:\Users\user1\Desktop\TTL\cmd\' ;;;;ログイン情報を定義 username = 'root' password = 'password' fileopen fh hostlist 0 while 1 filereadln fh buf if result goto breakloop pause 2 strsplit buf separator address = groupmatchstr1 hostname = groupmatchstr2 msg = address strconcat msg ':22 /ssh /nosecuritywarning /auth=password /user=' strconcat msg username strconcat msg ' /passwd=' strconcat msg password connect msg wait '>' sendln 'en' wait '#' ;;;;コマンド読み込み commandlist = commandlist_path strconcat commandlist hostname strconcat commandlist '.txt' fileopen fc commandlist 0 while 1 filereadln fc command if result = 1 then break endif sendln command pause 1 endwhile fileclose fc sendln 'exit' endwhile :breakloop fileclose fh end |