Skip to content

Instantly share code, notes, and snippets.

@Artistan
Created May 9, 2018 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artistan/981e4b20e539b092b018fa1ad20e1219 to your computer and use it in GitHub Desktop.
Save Artistan/981e4b20e539b092b018fa1ad20e1219 to your computer and use it in GitHub Desktop.
catail.sh :: cat files found in a tails search....
# thanks to some help
# https://unix.stackexchange.com/questions/442672/how-to-continuously-tail-a-log-find-all-files-sed-and-display-cat-the-foun
# https://stackoverflow.com/a/26884607/372215
# catail \"/var/log/httpd/modsec_audit.log\" 's/[^\/]*/\./;s/].*$//g'
# parameter 1 is the file(s) to log
# parameter 2 is the sed regular expression (regex) to search for files within the tailed log
# notice the example modsec_audit, this will log file in the audit.log that it wroe if you are logging output in Concurrent mode.
catail() (
if [[ -z "$1" || -z "$2" ]]; then
echo "catail \"/var/log/httpd/modsec_audit.log\" 's/[^\/]*/\./;s/].*$//g'"
return
fi
tail -f "$1" | while read line; do
echo "$line" | sed "$2" | awk '{print $0}' | xargs -n1 cat
done
)
# source catail
# catail \"/var/log/httpd/modsec_audit.log\" 's/[^\/]*/\./;s/].*$//g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment