踏み台経由の単体試験(CentOS8)用TeraTermマクロを作成してみました

TeraTermマクロ-機器情報を自動収集してくれるMACRO
https://www.j-oosk.com/teraterm/macro/256/
↑こちらのサイトを参考に構築時の単体試験(CentOS8)用TeraTermマクロを作成してみました。

1.単体試験(CentOS8)とは
ここでの単体試験はCentOS8がパラメータシート通りに設定されていることを確認する為の
設定パラメータの確認テストを指します。
NIC冗長試験や電源再起動も単体試験に含まれますが、
このマクロには障害試験のテスト手順は含まれません。

2.ファイル構成
tantai_test.ttl :単体試験(CentOS8)用マクロ
hostlist.txt :接続先IP一覧

3.マクロ処理概要
接続先IPが記述されたhostlist.txtを読み込んで、
接続先に踏み台(HOSTIP1st)経由で順次ログインして単体試験(CentOS8)のログを取得します。

4.接続先一覧の作成

hostlist.txt

192.168.0.35
192.168.0.36

5.踏み台経由の単体試験(CentOS8)用マクロ
tantai_fumidai_test.ttl

;============================================== 
; Filename    : tantai_fumidai_test.ttl
; Description : SSH tantai fumidai test macro
; Author      : takayuki
; Created     : 2020/12/14
; modified    : 
;============================================== 
;; 踏み台・作業対象サーバ/ユーザ名/パスワード設定 
HOSTIP1st = '192.168.0.33'
USERNAME1st = 'root'
PASSWORD1st = 'password'
USERNAME2nd = 'root'
PASSWORD2nd = 'password'
;; ログ保存先指定 
LOGSPATH = 'E:\TEMP\logs\'
;; ホスト一覧ファイル指定 
HOSTFILE = 'E:\TEMP\logs\hostlist.txt' 
;============================================== 
;; ①ホスト一覧ファイルオープン 
fileopen HOSTLIST HOSTFILE 0
 
;; ②ホスト一覧ファイルから接続ホスト(一行)読み込み 
filereadln HOSTLIST HOSTNAME
 
;; ③ホスト一覧ファイルのEOFまで繰り返し実行 
while result = 0 
;; ④空白行の場合、次の行を読み込む 
strlen HOSTNAME 
if result = 0 goto END 
;; ⑤先頭行がコメント(#)ではない場合、サブルーチン「SETSUZOKU」を実行 
strmatch HOSTNAME '^#'
if result <> 1 CALL SETSUZOKU
 
:END 
;; ⑥ホスト一覧ファイルからホスト名を読み込む 
filereadln HOSTLIST HOSTNAME 
endwhile
 
;; ⑦ホスト一覧ファイルクローズ 
fileclose HOSTLIST
 
;; ⑧マクロ終了 
end 
;=========================================
 
;; *****サブルーチン***** 
:SETSUZOKU
;wait時間
ptime = 500

;ホスト名を取得
;gethostname hostname
 
;;現在日時を取得しつつ、ファイル名の一部を構築
gettime timestr '_%Y%m%d_%H%M%S.log'

;文字列を連結してファイル名を構築
logfileName = HOSTNAME
strconcat logfileName timestr
FULLPATH = LOGSPATH 
strconcat FULLPATH logfileName

;; 踏み台サーバへSSH接続
;; ①接続用コマンド組立て
COMMAND = HOSTIP1st
strconcat COMMAND ':22 /ssh /2 /auth=password /user='
strconcat COMMAND USERNAME1st
strconcat COMMAND ' /passwd='
strconcat COMMAND PASSWORD1st
 
;; ②踏み台サーバへ接続
connect COMMAND
 
;; ③プロンプトが表示されるのを待機
wait '$' '#'

;; 作業対象サーバへSSH接続
;; ④接続用コマンド組み立て
HOSTIP2nd = HOSTNAME

COMMAND = 'ssh '
strconcat COMMAND USERNAME2nd
strconcat COMMAND '@'
strconcat COMMAND HOSTIP2nd
 
;; ⑤作業対象サーバへ接続
sendln COMMAND
 
;; ⑥パスワード入力
wait 'password:'
sendln PASSWORD2nd
 
;; ログ取得開始 
logopen FULLPATH 0 0 
logwrite '*********************************'#13#10
logwrite '■ホスト名 : ' 
logwrite HOSTNAME
logwrite #13#10
logwrite '*********************************'#13#10

 
;; 情報取得
mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■1-1 ホスト名設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'hostname' 

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■1-5 OS起動後のdmesg確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'dmesg' 

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■1-6 OS起動後のmessages確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'tail -3000 /var/log/messages' 

mpause ptime

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■2-1 搭載CPUの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /proc/cpuinfo'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■2-2 搭載メモリの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /proc/meminfo'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■2-4 ホスト名の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'hostname'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■2-5 RHELバージョンの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/redhat-release'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■2-6 アーキテクチャカーネルバージョンの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'uname -a'

mpause ptime

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-1 言語の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/locale.conf'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-2 キーボード設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'localectl status'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-5 タイムゾーンの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'timedatectl status'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-7 ディスクパーティションの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'df -hT'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-8 swapパティションの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'swapon -s'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-9 GRUBブートローダの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'efibootmgr -v | grep centos'

mpause ptime
wait ']#' 
sendln 'grep gnu-linux /etc/grub.d/10_linux'

mpause ptime
wait ']#'
sendln 'cat /etc/grub.d/40_custom'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■3-10 パッケージの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'yum list installed'

mpause ptime

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-3 ユーザ設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/passwd'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-4 NTP設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/chrony.conf'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-5 kdump設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'kdumpctl status'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-6,4-10 ネットワーク設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/sysconfig/network-scripts/ifcfg-bond0'

mpause ptime
wait ']#' 
sendln 'cat /etc/sysconfig/network-scripts/ifcfg-bond1'

mpause ptime
wait ']#' 
sendln 'cat /etc/sysconfig/network-scripts/ifcfg-ens192'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-11 ネットワーク設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'ip addr'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-12 ネットワーク設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'nmcli -t con show bond0'

mpause ptime
wait ']#'
sendln 'nmcli -t con show bond1'

mpause ptime
wait ']#'
sendln 'nmcli -t con show ens192'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-15 デフォルトゲートウェイの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'ip route'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■4-16 DNSの設定確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/resolv.conf'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定1-1 通信速度の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'ethtool bond0'

mpause ptime
wait ']#'
sendln 'ethtool bond1'

mpause ptime
wait ']#'
sendln 'ethtool ens192'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定1-2 静的ルートの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'ip route'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定1-5 追加エントリの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/hosts'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定1-6 bonding設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /proc/net/bonding/bond0'

mpause ptime
wait ']#'
sendln 'cat /proc/net/bonding/bond1'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定3-1 ファイアウォール設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'firewall-cmd --list-all'

mpause ptime
wait ']#'
sendln 'systemctl --no-pager status firewalld'

mpause ptime
wait ']#'
sendln 'iptables -L'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定3-2 SELinux設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln '/usr/sbin/getenforce'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定3-4 kdump出力先設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/kdump.conf'

mpause ptime
wait ']#'
sendln 'cat /etc/kdump.conf | grep path | egrep -v "#"'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定3-5 kdump取得設定の確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /proc/cmdline'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定3-8 起動ランレベルの確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'systemctl get-default'

mpause ptime
logwrite #13#10
logwrite '*********************************'#13#10
logwrite '■オプション設定4-4 ssh接続確認'
logwrite #13#10
logwrite '*********************************'#13#10
mpause ptime
wait ']#'
sendln 'cat /etc/ssh/sshd_config | grep PermitRootLogin'

mpause ptime
 
closett 
return 
;; *****サブルーチン終わり*****
Comments are closed.