NETWORK ENGINEER BLOG

Tips and Reviews for Engineers

TeraTerm マクロ例

踏み台サーバー(192.168.1.100)を経由して、複数の NetApp の aggregate と volume の使用量を収集するマクロです。任意の Host(192.168.1.101-105)に、巡回アクセスして "df -Ag" と "df -h"を実行します。

connect '192.168.1.100 /ssh /auth=password /user=root /passwd=default'
wait '$'

;================ logopen ================
getdir DIR
getdate DATE
gettime TIME
strcopy TIME 1 2 HH
strcopy TIME 4 2 MM
strcopy TIME 7 2 SS
LOG = DIR
strconcat LOG '\'
strconcat LOG DATE
strconcat LOG '_'
strconcat LOG HH
strconcat LOG MM
strconcat LOG SS
strconcat LOG '_'
strconcat LOG 'netapp.log'
logopen LOG 0 1

;================ login ================
sendln
wait '$'
for i 1 1           ※192.168.1.101 でのみ実行したい場合
;for i 1 5          ※192.168.1.101-105 で実行したい場合
  if i =  1 then
    HOST = '192.168.1.101'
  elseif i =  2 then
    HOST = '192.168.1.102'
  elseif i =  3 then
    HOST = '192.168.1.103'
  elseif i =  4 then
    HOST = '192.168.1.104'
  elseif i =  5 then
    HOST = '192.168.1.105'
  endif
  PR = HOST
  strconcat PR '> '
  sendln 'ssh -l root ' HOST
  wait 'password:'
  sendln 'default'
  wait PR
;================ command ================
  sendln 'df -Ag'
  wait PR
  sendln 'df -h' 
  wait PR
;================ logout =================
  sendln 'logout telnet'
  wait '$'
next

;================ logclose ================
logclose
sendln 'exit'
広告を非表示にする