LoginSignup
1
0

More than 5 years have passed since last update.

tera tarmマクロ 作成用メモ

Posted at

【前提条件】
・現在使用しているTera Tarmのバージョン「4.9.3」
・複数機器にログイン・汎用性を持たせるために別紙テキストを読み込む用作成
・下記テキストを作成 ※直接記載で下記テキストは不要でもOK
 -OV.txt
  ⇒踏み台として利用する機器名・IPアドレス
 -hozon.txt
  ⇒出力したログを置く場所指定。ディレクトリパスを記載
 -host_ipadd.txt
  ⇒ログ取得対象のIPアドレスと機器名
 -show_comm.txt
  ⇒取得コマンド一覧

【任意の名前.ttl】
*****************************
;;;外部ファイルを開いて「login」にファイルの内容を格納。「0」はファイルの頭から読み込み
fileopen login 'host_ipadd.txt' 0
:LOOP

;;;fileopenで読んだ「login」から一行読み出し、「host_nmif・host_ip」に格納
filereadln login host_nmif result goto filclose
filereadln login host_ip
if result goto filclose

;log保存先フォルダ読み込み

fileopen log_outp 'hozon.txt' 0
filereadln log_outp log_outp2
fileclose log_outp

fileopen springboard 'OV.txt' 0
conchk = 1

:SPRINGBOARDLOOP

filereadln springboard springboard_nm
if result goto LOG_GET
filereadln springboard springboard_ip
if result goto LOG_GET

;;「springboard_nm」で格納した内容に「'#'」を追加する
strconcat springboard_nm '#'
if conchk = 1 then
strconcat springboard_ip ':23 /nossh /T=1'
connect springboard_ip
wait 'Username:'
sendln 'cisco'
wait 'Password:'
sendln 'cisco'
else
Telnet = 'telnet '
strconcat Telnet springboard_ip
sendln Telnet
wait 'Password:' '#'
sendln 'cisco'
wait springboard_nm '#'
endif

conchk = conchk+1
goto SPRINGBOARDLOOP

:LOG_GET
fileclose springboard

mpause 50

;; ログファイル名の設定
;日時とホスト名入れる場合
getdate strLOG_NAME "%Y%m%d%H%M%S"

strLOG_FILE = log_outp2
strconcat strLOG_FILE host_name
strconcat strLOG_FILE strLOG_NAME
strconcat strLOG_FILE '.log'
strconcat host_name '#'

if conchk = 1 then
strconcat host_ip ':23 /nossh /T=1'
connect host_ip
wait 'Password:'
sendln 'cisco'
wait host_name
else
Telnet = 'telnet '
strconcat Telnet host_ip
sendln Telnet
wait 'Password:' '#'
sendln 'cisco'
wait host_name '>' '#'
sendln 'enable'
wait 'Password:' '#'
sendln 'cisco'
wait host_name '#'
endif

setsync 1
;; ログ取得開始
logopen strLOG_FILE 1 1
timeout=300
fileopen list 'show_comm.txt' 0
mpause 200

while 1
;ファイルから1行読む
filereadln list line2

;最終まで読み込んでいたらループを抜ける
if result = 1 break

;読み込んだコマンドを実行
flushrecv
sendln line2
wait '--More--' host_name '[confirm]' '#'
mpause 50

if result = 1 then
sendln $03
mpause 10
fileclose list
end
endif

flushrecv
endwhile

fileclose list

mpause 100
sendln ''
wait host_name '#'
mpause 50
while conchk > 1
sendln 'exit'
wait 'closed'
mpause 50
conchk = conchk - 1
endwhile
setsync 0
sendln 'exit'
logclose

unlink
goto LOOP

:filclose
fileclose login
*****************************
マクロがうまく動作しない場合は、
messageboxや変数を利用してうまく動作しない部分を調査する。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0