Last active
March 29, 2020 20:03
-
-
Save davispeixoto/eeb378e52cda76744ef5f7fe51fe3d2e to your computer and use it in GitHub Desktop.
Shell script - BASH - for filtering entries on log from the last 10 minutes only
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 | |
## Usage | |
# save the contents of this file to a executable file, | |
# call it, passing the target log file as first argument | |
# apapt the lines below for match your log file format | |
dates=("`date --date="-10 min" "+%_d %H:%M"`" \ | |
"`date --date="-9 min" "+%_d %H:%M"`" \ | |
"`date --date="-8 min" "+%_d %H:%M"`" \ | |
"`date --date="-7 min" "+%_d %H:%M"`" \ | |
"`date --date="-6 min" "+%_d %H:%M"`" \ | |
"`date --date="-5 min" "+%_d %H:%M"`" \ | |
"`date --date="-4 min" "+%_d %H:%M"`" \ | |
"`date --date="-3 min" "+%_d %H:%M"`" \ | |
"`date --date="-2 min" "+%_d %H:%M"`" \ | |
"`date --date="-1 min" "+%_d %H:%M"`" \ | |
"`date --date="-0 min" "+%_d %H:%M"`" \ | |
); | |
command_line="grep -E \""; | |
for i in "${dates[@]}" | |
do | |
command_line="$command_line$i|" | |
done | |
MAX=${#command_line} | |
MAX=$(($MAX-1)); | |
# checking the str length to remove the last pipe on regex | |
# echo $MAX; | |
command_line=${command_line:0:$MAX} | |
command_line="$command_line\" $1" | |
# checking the command to be run | |
# echo $command_line | |
output=$(eval "$command_line") | |
echo "$output"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment