1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Teraterm マクロ作ってみた

Last updated at Posted at 2024-12-17

前置き

LinuxサーバへteratermからSSH接続する際に逐一ログ設定やid/passを入力することが億劫であったためマクロを作成した。

汎用性を上げるために、パラメータを変更することで誰でも簡易にアクセスできることを可能にした。

ファイルを作成し、拡張子を .ttl にする
下記コードの条件に沿うようにマクロとログ保存用フォルダを用意する

実現できること

・逐一ログインID/Passは不要
・起動と同時にログ取得開始
・現在バッファを含むこと可能(有効化/無効化 → 選択可能)
・タイムスタンプデフォルト付与(有効化/無効化 → 選択可能)
・ログファイル名に自動で作業日時、サーバホスト名付与

マクロコード

;ログイン情報(変数の定義)
;-------------------------------------------------------------------------------------------

username = 'xxxx'          				; ログインするサーバーのユーザー名 例:root
hostip	 = 'xx.xx.xx.xx'				; ログインするサーバーのホスト名またはIPアドレス
portnum  = 'xx'							; SSHを指定 例:22
passwd   = 'xxxxx'						; パスワードを入力 例:admin1234
hostname = 'xxxxxxxxxxxx'			    ; ホスト名

;-------------------------------------------------------------------------------------------

;ログファイルの生成 (変数を定義し生成するログファイルに文字列として結合)
;生成例: [マクロのディレクトリ]\[ログ格納ディレクトリ]\[ホスト名]\[作業者名]_[ホスト名]_[タイムスタンプ].log
;-------------------------------------------------------------------------------------------

inputbox '作業者名を入力してください' 'User名入力' ; マクロ起動時ダイアログ表示
getdir dir								; マクロを配置しているdirを取得
gettime timestr "%Y%m%d_%H%M%S.log"		; logfile名に埋め込む時刻(yyyymmddhhmmss)を取得

strconcat filename dir
strconcat filename '\xxxxxxx\'      ; ログ保存ディレクトリ 例:01_LoG
strconcat filename hostname
strconcat filename '\'
strconcat filename inputstr             ; ダイアログに入力したテキスト 例:作業者名
strconcat filename '_'
strconcat filename hostname
strconcat filename '_'
strconcat filename timestr        ; 上記で定義した日時情報

;-------------------------------------------------------------------------------------------

;ログイン実施・ログの書き込み開始
;-------------------------------------------------------------------------------------------

msg = hostip
strconcat msg ':portnum /ssh /auth=password /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg passwd
connect msg

sendln ''  ; 現在バッファを含む
logopen filename 0 1 0 1 ; ログ記録を開始(タイムスタンプ有効)
;logopenコマンドのビット左から
;<バイナリ><追記するかどうか><プレーンテキスト><timestamp入れるか入れないか>
;有効化する際は"1",無効化する際は"0"にする

;-------------------------------------------------------------------------------------------



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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?