1
0
Fork 1

Update pull-logs.sh

This commit is contained in:
colin 2024-09-28 12:06:55 -04:00
parent d63412221f
commit 30f50dcb0f
1 changed files with 14 additions and 4 deletions

View File

@ -37,7 +37,6 @@ get_var_log_logs() {
if [[ -f $log ]]; then
echo "Logs from $log"
awk -v start="$START" -v end="$END" '{
# Extract date and time from each line depending on log format
logtime = $1 " " $2 " " $3
logtime_epoch = mktime(gensub(/-|:/, " ", "g", logtime))
start_epoch = mktime(gensub(/-|:/, " ", "g", start))
@ -56,16 +55,27 @@ get_var_log_logs() {
get_service_logs() {
echo "----- Service Logs (nginx, apache, mysql, etc.) -----"
# Add specific service logs as needed
service_logs=(/var/log/nginx/access.log /var/log/nginx/error.log /var/log/apache2/access.log /var/log/mysql/error.log)
for log in "${service_logs[@]}"; do
if [[ -f $log ]]; then
echo "Logs from $log"
awk -v start="$START" -v end="$END" '{
# Similar to /var/log, but make adjustments if needed for service-specific formats
logtime = $1 " " $2
logtime_epoch = mktime(gensub(/-|:/, " ", "g", logtime))
start_epoch = mktime(gensub(/-|:/, " ", "g", start))
end_epoch = mktime(gensub(/-|:/, " ", "g", end))
if (logtime_epoch >= start_ep
if (logtime_epoch >= start_epoch && logtime_epoch <= end_epoch) {
print $0
}
}' $log
else
echo "$log not found, skipping..."
fi
done
}
# Fetch logs
get_journalctl_logs
get_var_log_logs
get_service_logs