Going through different log files can be a pain, but here’s a simple script that parses today’s logs from different files into a single file, in this case we extract today’s logs from messages, auth.log, syslog. Finally, we send them through email. Don’t forget to make the file executable!… Logparser can be downloaded from here
#!/bin/bash #author jorge #purpose: extracting daily log entries from multiple log files LOG1=/var/log/messages LOG2=/var/log/auth.log LOG3=/var/log/syslog MYDATE=`date +%b\ %d` OUTPUTLOG=`date +%F`.dailylog EMAIL=btuser for LOG in $LOG{1,2,3} do #if file exist and is not empty then process if [ -e $LOG ] && [ -s $LOG ]; then echo $LOG BEGIN >> $OUTPUTLOG #only grabbing todays log out of file grep -E "$MYDATE" $LOG >> $OUTPUTLOG 2>/dev/null echo $LOG END >> $OUTPUTLOG echo >> $OUTPUTLOG fi done #email output cat $OUTPUTLOG | mail -s "daily logs `date +%F`" $EMAIL 2>/dev/null #END