How to continuously tail a log, find all files (sed), and display (cat) the found files
2
votes
2
answers
4934
views
How to I continuously
tail -f
a log, find all files (sed
), and display (cat
) the found files
## example data in audit logs.
tail -f /var/log/httpd/modsec_audit.log | sed 's/[^\/]*/\./;s/].*$//g'
### output
./apache/20180508/20180508-1428/20180508-142802-WvH6QgoeANwAAMwsFZ4AAAAF
./apache/20180508/20180508-1428/20180508-142803-WvH6QgoeANwAAMwtFfcAAAAG
./apache/20180508/20180508-1428/20180508-142803-WvH6QwoeANwAAMwuFlUAAAAH
./apache/20180508/20180508-1513/20180508-151357-WvIFBQoeANwAAMwnE@4AAAAA
./apache/20180508/20180508-1513/20180508-151357-WvIFBQoeANwAAMwoFD8AAAAB
./apache/20180508/20180508-1516/20180508-151608-WvIFiAoeANwAAMz1FSwAAAAA
./apache/20180508/20180508-1516/20180508-151609-WvIFiQoeANwAAMz2FYIAAAAB
./apache/20180508/20180508-1516/20180508-151611-WvIFiwoeANwAAMz3FeEAAAAC
./apache/20180508/20180508-1516/20180508-151611-WvIFiwoeANwAAMz4Fj4AAAAD
./apache/20180508/20180508-2112/20180508-211205-WvJY9QoeANwAAM1MFCoAAAAA
### works with echo
echo "./apache/20180508/20180508-1428/20180508-142802-WvH6QgoeANwAAMwsFZ4AAAAF" | sed 's/[^\/]*/\./;s/].*$//g' | awk '{print $0}' | xargs cat
### works with cat
cat /var/log/httpd/modsec_audit.log | sed 's/[^\/]*/\./;s/].*$//g' | awk '{print $0}' | xargs cat
### does not work with tail...
tail -f /var/log/httpd/modsec_audit.log | sed 's/[^\/]*/\./;s/].*$//g' | awk '{print $0}' | xargs cat
I assume the tailing does not work because the script never terminates and sed
is still caching the results until termination of the script.
***Is there a way to make this work, continuously?***
Asked by Artistan
(463 rep)
May 9, 2018, 03:28 AM
Last activity: Sep 12, 2024, 12:35 PM
Last activity: Sep 12, 2024, 12:35 PM