~構成情報取得用スクリプト~
製品の構成情報取得を例にcatやls等、簡単なコマンドを大量に打たなければならない場面で活用できるスクリプトを作成しt。
#!/usr/bin/ksh
#変数定義
#---------------------------------------------------------------------
HOST_NAME=$(uname -n)
DIRNAME=$(cd $(dirname $0); pwd)
UTLSTFILE=${DIRNAME}/ut.lst
UT_LOG=${DIRNAME}/${HOST_NAME}_WAS_ut.log
UT_IHS_LOG=${DIRNAME}/${HOST_NAME}_WAS_utihs.log
ENTER="\n\n"
TEMPL="/work/_kibantrash/WAS/templates"
NAME=$(echo ${HOST_NAME} | cut -c 5-8 )
mv ${UT_LOG} ${UT_LOG%.log}_$(date +%Y%m%d%H%M).log
case "${NAME}" in
"TEST" ) APNAME="test" ;;
"TEST1" ) APNAME="test1" ;;
"TEST2" ) APNAME="test2" ;;
"TEST3" ) APNAME="test3" ;;
* ) echo "対象サーバーではありません"
exit 1
esac
#リストファイル存在確認
if [ ! -f ${UTLSTFILE} ]; then
echo "【×】 ${UTLSTFILE}が見つかりません。 処理を中止します。"
exit 1
fi
#ユーザー確認
if [ $(whoami) != root ]; then
echo "rootユーザーで実行してください"
exit 1
else
echo "===============================================================" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
echo "対象サーバー : ${HOST_NAME}" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
echo "実施ユーザー : $(whoami)" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
echo "実施日時 : $(date)" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
echo "" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
fi
UTNUMBER_PRV="-"
TYPE_PRV="-"
cat ${UTLSTFILE} | grep -v ^# | while read LINE; do
TYPE=$( echo ${LINE} | awk -F'[,]' '{print $1}')
UTNUMBER=$( echo ${LINE} | awk -F'[,]' '{print $2}')
DETAILES=$( echo ${LINE} | awk -F'[,]' '{print $3}')
COMMAND=$( echo ${LINE} | awk -F'[,]' '{print $4}')
if [ ${TYPE} == WAS ]; then
LOG=${UT_LOG}
else
LOG=${UT_IHS_LOG}
fi
if [ ${TYPE} != ${TYPE_PRV} ]; then
echo "===============================================================" | tee -a ${LOG}
echo "${TYPE}_UT" | tee -a ${LOG}
echo "" | tee -a ${LOG}
fi
if [ ${UTNUMBER} != ${UTNUMBER_PRV} ]; then
echo "===============================================================" | tee -a ${LOG}
echo "◆◆◆${UTNUMBER} : ${DETAILES}◆◆◆" | tee -a ${LOG}
else
echo "" | tee -a ${LOG}
fi
eval "echo \"[CMD:${COMMAND}]\"" | tee -a ${LOG}
eval ${COMMAND} 2>&1 | tee -a ${LOG}
echo "" | tee -a ${LOG}
UTNUMBER_PRV=${UTNUMBER}
TYPE_PRV=${TYPE}
done
echo "===============================================================" | tee -a ${UT_LOG} | tee -a ${UT_IHS_LOG}
exit 0
スクリプト内部で読み込まれるスクリプトファイル ↓
## WAS・IHS UT用リストファイル
IHS,UTWS00001,httpd.conf確認,ls -l /opt/IBM/HTTPserver/conf/httpd.conf
IHS,UTWS00002,mime.types確認,ls -l /opt/IBM/HTTPserver/conf/mime.types
IHS,UTWS00003,状態確認,ps -ef | grep httpd
WAS,UTWS00011,server.xml確認,cat /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml
WAS,UTWS00011,server_dvmobile_db_conf.xml確認,cat /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.env
WAS,UTWS00013,/opt確認,ls -ld /opt
IHS,UTWS00014,アプリケーションサーバー状態確認,ps -ef | grep ${APNAME}_Server01
WAS,UTWS00015,バックアップ確認,/opt/IBM/WebSphere/Liberty/bin//server package ${APNAME}_Server01 --server-root=./usr --include=usr --archive=/Backup/WAS/dvmobile_usr_Backup.zip;echo $?
WAS,UTWS00015,バックアップ確認,mv /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml.old
WAS,UTWS00015,バックアップ確認,cd /opt/IBM/WebSphere/Liberty;pwd;unzip -n /Backup/WAS/dvmobile_usr_Backup.zip -d /opt/IBM/WebSphere/Liberty
WAS,UTWS00015,バックアップ確認,ls -l /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml
WAS,UTWS00015,バックアップ確認,diff /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml /opt/IBM/WebSphere/Liberty/usr/servers/${APNAME}_Server01/server.xml.old
実施ログ(一部) ↓
===============================================================
対象サーバー : SCWHTEST02
実施ユーザー : root
実施日時 : 2023年 7月 7日 金曜日 13:26:13 JST
===============================================================
WAS_UT
===============================================================
◆◆◆UTWS00011 : server.xml確認◆◆◆
[CMD:cat /opt/IBM/WebSphere/Liberty/usr/servers/TEST_Server01/server.xml]
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.3</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
</server>
[CMD:cat /opt/IBM/WebSphere/Liberty/usr/servers/TESTmobile_Server01/server.env]
keystore_password=g1CYbF1zc4xQd2H8vQZjGr9
===============================================================
◆◆◆UTWS00013 : /opt確認◆◆◆
[CMD:ls -ld /opt]
drwxr-xr-x. 4 root root 29 5月 11 17:02 /opt
===============================================================