Created
October 3, 2024 15:14
-
-
Save imksoo/e9a77d6fa29b51295fee84fa515a4dbc to your computer and use it in GitHub Desktop.
NTT HGW PR-400NEのログを取得して保存するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# NTT HGWのIPアドレス、ユーザ名、パスワードを設定 | |
HGW_ADDR=192.168.1.1 | |
USERNAME=user | |
PASSWORD=p@ssw0rd | |
mkdir -p logs | |
# NTT HGWのログを取得 | |
function get_log { | |
LOG_NAME=$1 | |
DATETIME=$(date +"%Y%m%d-%H%M") | |
curl -s -o logs/${LOG_NAME}_${DATETIME}.log http://${USERNAME}:${PASSWORD}@${HGW_ADDR}/index.cgi/${LOG_NAME}.log | |
} | |
# 2つのログファイルの差分を取得し、新しいログファイルに追記 | |
function append_new_logline_to_log { | |
LOG_NAME=$1 | |
# logsフォルダの中でLOG_NAMEで始まる最新のログファイルを取得 | |
NEW_LOG=$(ls -1 logs/${LOG_NAME}_*.log | tail -n 1) | |
# logsフォルダの中でLOG_NAMEで始まる最新から2番目のログファイルを取得 | |
OLD_LOG=$(ls -1 logs/${LOG_NAME}_*.log | tail -n 2 | head -n 1) | |
# 2つのログファイルの差分を取得し、新しいログファイルに追記 | |
sort ${OLD_LOG} ${OLD_LOG} ${NEW_LOG} | uniq -u >> ${LOG_NAME}.log | |
} | |
# NTT HGWのログを取得 | |
LOGS=("system_inf" "system_tel" "system_sec") | |
for LOG in ${LOGS[@]}; do | |
get_log ${LOG} | |
append_new_logline_to_log ${LOG} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment