Help on script to capture info on log file for a particular time frame

Hi

I have a system running

 uname -a
Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux

I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email.

I was thinking in set a cron entry at that time to

tail -f > filename

, them

mailx 

the file, but I am not sure how to stop capturing data at 11:30AM.
Can I have some help on this

Perhaps something like:

#!/bin/ksh
date=$(date)
tail -f /var/log/syslog > /tmp/loglog.$$ &
tailpid=$!
#echo "tailpid is $tailpid"
sleep 1800
kill $tailpid
mailx -s"30 minute log from $date" user@company.com < /tmp/loglog.$$
rm /tmp/loglog.$$
1 Like

Thank you very much, it worked beatifully