2007年1月16日火曜日

TeraTermのマクロ(ログ)

TeraTermのマクロを利用して常にログが取れるようにしておく。
仕事柄ログを取っていなくて泣く事も多いので予防処置。ネット上で参考になるサンプルを見つけたので使わせてもらう事にします。

;; -------------------------------------
;; TeraTerm ログスクリプト
;; 作成日 2007.01.16
;; -------------------------------------

;; -------------------------------------
;; 変数定義
;; -------------------------------------

;; ログの置き場所
strLogPath = 'C:\TEMP\\'

;; ログファイル名の先頭につける文字列
strPrefix = 'TTM'

;; 作業者名
inputbox '作業者名' 'User Name'
strLogUsername = inputstr

;; コメントの取得
inputbox '作業名' 'comment'
strLogComment = inputstr

;; システム日付の取得
getdate strDate
strcopy strDate 1 2 strYear
strcopy strDate 6 2 strMonth
strcopy strDate 9 2 strDay

;; システム時刻の取得
gettime strTime
strcopy strTime 1 2 strHour
strcopy strTime 4 2 strMinute
strcopy strTime 7 2 strSecond

;; ログファイルの拡張子
strExtension = '.log'


;; ログ名
strLogfile = strLogPath
strconcat strLogfile strPrefix
strconcat strLogfile '-'
strconcat strLogfile strYear
strconcat strLogfile strMonth
strconcat strLogfile strDay
strconcat strLogfile strHour
strconcat strLogfile strMinute
strconcat strLogfile strSecond
strconcat strLogfile '-'
strconcat strLogfile strLogUsername
strconcat strLogfile '-'
strconcat strLogfile strLogComment
strconcat strLogfile strExtension

messagebox strLogfile 'debug'

;connect "

;; -------------------------------------
;; 実行部
;; -------------------------------------

fileopen F strLogfile 0
filewriteln F '============================='
filewrite F 'Tera Term Logfile : '
filewriteln F strLogfile
filewriteln F '============================='
filewriteln F ''
fileclose F

logopen strLogfile 0 1

;; --- EOF ---


これでTeraTermを起動して接続先の入力箇所で 「127.0.0.1 /m=log.ttl」の様に起動すればログが取られる。一定のルールで常にとり続ける事が肝心。個人だけで使うなら使用者とか入らないし、Loginユーザがキチンと使い分けられているならEnvから取ってきて自動で入れても良いかも知れない。

参考

0 コメント: