Hi,
I am trying to view log files using GREP and
variable substitution. Let's say a user wants to view a log file for "Sep
30" Here is the shell (BASH) script that I put together for
it.
#!/bin/sh
cd
/routerlogs
echo date echo date=`date | cut -c5-7` echo "Which Date Do You Wish to Parse?:"; read dte; echo "Searching....." grep -e "$date $dte" *.log | grep -e WARNING It assumes the month as current...(That's a problem
for October) but that's not the only problem. The syslog text that it's
reading works fine for double digit date fields, but not for single...allow me
to explain.
Sep 30 comes in the syslog as "Sep(space)30"
Oct 1 comes in as "Oct(space)(space)1" thus screwing up my grep on
the double digit date field.... Is there a better way to "grep" for info
out of a text file?
Here is my script for viewing "archive" files and
works nicely after logrotations, but what about the active logs?
#!/bin/sh
cd /var/log/routerlogs/old echo date echo "Current Week of the Year is: `date +%U`" date=`date | cut -c5-7` week=`date +%U` echo "Which Week Do You Wish to Parse?:"; read week; echo "Do You wish to sort by day also?:"; read ans; if [ $ans != y ]; then if [ $ans != n ]; then echo "Please re-enter using 'y' or 'n'";read ans if [ $ans != y ]; then if [ $ans != n ]; then echo "Attempt at reading your input Unsuccessful. Exiting....";exit fi fi fi fi if [ $ans = y ]; then echo "Which Day?:";read dte; echo "Which Month?{eg.Sep}:";read mon; echo "Searching....." grep -e "$mon $dte" *.$week | grep -e WARNING else echo "Searching....." grep -e WARNING *.$week exit fi Again, works fine for single digit "grepping" but I
didn't realize that the SYSLOG input data for Oct 1 would have two spaces Vs.
one.
Brett
|
- Re: Viewing Text Output Brett Franck
- Re: Viewing Text Output Bret Hughes
- Re: Viewing Text Output Brett Franck
- Re: Viewing Text Output Bret Hughes