Home » Infrastructure » Unix » Coping alerrt log
Coping alerrt log [message #330629] Mon, 30 June 2008 11:41 Go to next message
toshidas2000
Messages: 120
Registered: November 2005
Senior Member
How do I copy one day of alertlog message to a file??

grep does not work, it just copies the date
Re: Coping alerrt log [message #330690 is a reply to message #330629] Mon, 30 June 2008 17:45 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10626
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Something like this?
bash-2.03$ cat somescript
start=`grep -n "$1" alert_lawp1.log | head -1 |awk -F":" '{print $1}'`
end=`grep -n "$1" alert_lawp1.log | tail -1 |awk -F":" '{print $1"p"}'`
echo "Start line $start";
echo "End line $end";
sed -n $start,$end alert_lawp1.log > newLog


Above is not the best code and already has bugs. I am sure this
can be achieved in an efficient one-liner.
The search stops at the last found date stamp. Any messages after
last occurrence will not be considered.
Re: Coping alerrt log [message #330691 is a reply to message #330690] Mon, 30 June 2008 17:53 Go to previous message
Mahesh Rajendran
Messages: 10626
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
>>.Any messages after last occurrence will not be considered.
Quoting myself
for the second scan to find last occurrence you may want to
use input date + one day and do head -1 instead of doing a tail.

bash-2.03$ cat somescript
start=`grep -n "$1" alert_lawp1.log | head -1 |awk -F":" '{print $1}'`
end=`grep -n "$2" alert_lawp1.log | head -1 |awk -F":" '{print $1"p"}'`
echo "Start line $start";
echo "End line $end";
sed -n $start,$end alert_lawp1.log > newLog
bash-2.03$ somescript "Fri Jun 27" "Sat Jun 28"
Start line 16800
End line 16912p
Previous Topic: Positional Parameters Resetting
Next Topic: ORA-27102.(OUT OF MEMORY)
Goto Forum:
  


Current Time: Sun Sep 21 13:17:03 CDT 2014

Total time taken to generate the page: 0.18913 seconds