Architecture/WAS
[스크립트] 날짜와 배포ID로 로그파일 조회하기
GOMSHIKI
2024. 4. 2. 11:50
반응형
- 로그 파일에서 변수로 날짜와 배포ID를 받아 배포 결과를 조회하는 스크립트
- shell : ksh
- 변수 : yyyymmdd, 배포ID
#!/bin/ksh
# Check if the number of arguments is correct
if [ $# -ne 2 ]; then
echo "[Usage] : deploy_chk.sh yyyymmdd ID or deploy_chk.sh ID yyyymmdd"
exit 1
fi
# Function to check if the argument is a date
is_date() {
case $1 in
[0-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]) return 0 ;;
*) return 1 ;;
esac
}
# Check and assign the date and ID based on the input
if is_date $1; then
date=$1
id=$2
elif is_date $2; then
date=$2
id=$1
else
echo "Invalid input. Please provide a date in yyyymmdd format and an ID."
exit 1
fi
# Extract year, month, and day from the date
Y_day=$(echo $date | cut -c 1-4)
M_day=$(echo $date | cut -c 5-6)
D_day=$(echo $date | cut -c 7-8)
# Check if the log file exists and then search for the ID and "결과"
log_file="/LOGS/klaf/.../webadmin.log.${Y_day}-${M_day}-${D_day}"
if [ -f $log_file ]; then
grep "$id" $log_file | grep "결과"
else
echo "Check Day or ID"
exit 1
fi
반응형