How can I search through the entire maillog archive for a line containing a specific word?
I use "cat /var/log/maillog |grep myword" for searching in the current log but I don't know how to search through the archived logs as well.
Many distros compress the rotated logfiles, normally with gzip. In that case, use gzip to decompress it (-d) but tell it not to write the uncompressed file, instead send it to stdout (-c):
Code:
for LOG in `ls /var/log/maillog*.gz`
do
echo ${LOG}
gzip -dc ${LOG} | grep myword
done
The gzip package also comes with a nifty little utility called zcat which does the same thing as gzip -dc. You could use zcat in place of gzip -dc in the code snippet above if you preferred.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.