cd /var/log/
cd ~/temp2
ls -l /etc/cron.daily
cat /etc/crontab
grep -E '`date +%b\ %d`' messages
grep -E 'Oct 15' messages -> results the mach line that contain 'Oct 15'
grep -E 'Oct 15' messages | wc -l -> results the number of lines
touch logabstract.sh -> how to abstract daily log
#!/bin/bash
mydate=`date +%b\ %d`
log1=/var/log/messages
log2=/var/log/maillog
echo $mydate
for log in $log{1,2}
do
echo $log BEGIN
grep -E "$mydate" $log # search for $mydate into $log file
echo $log END
echo
done
#END
. logabstract.sh -> enteries containing day chosen are displayed
. logabstract.sh 2> logabstract.errors #send to standard error
#!/bin/bash
mydate=`date +%b\ %d`
log1=/var/log/messages
log2=/var/log/maillogBAD
echo $mydate
for log in $log{1,2}
do
echo $log BEGIN
grep -E "$mydate" $log # search for $mydate into $log file
echo $log END
echo
done
#END
. logabstract.sh 2> logabstract.errors #send to standard error. Now we have error
#!/bin/bash
mydate=`date +%b\ %d`
log1=/var/log/messages
log2=/var/log/maillog
echo $mydate
for log in $log{1,2}
do
echo $log BEGIN
grep -E "$mydate" $log 2> logabstract.errors # 0 STD IN, 1 STD OUT, 2 STD ERROR
echo $log END
echo
done
#END
#!/bin/bash
mydate=`date +%b\ %d`
myscript=`basename $0`
myscripterrors=$myscript.errors
log1=/var/log/messages
log2=/var/log/maillog
echo $mydate
for log in $log{1,2}
do
echo $log BEGIN
grep -E "$mydate" $log 2> $myscripterrors # 0 STD IN, 1 STD OUT, 2 STD ERROR
echo $log END
echo
done
#END
. logabstract.sh -> the name of the created file is bash.errors
chmod u+x logabstract.sh
./logabstract.sh -> the name of the created file is logabstract.sh.errors
#!/bin/bash
mydate=`date +%b\ %d`
myscript=`basename $0`
myscripterrors=$myscript.errors
log1=/var/log/messages
log2=/var/log/maillog
echo $mydate
for log in $log{1,2}
do
if [ -e $log ] # this will be executed if log files log1 or log2 does not exists
then
echo $log BEGIN
grep -E "$mydate" $log 2> $myscripterrors # 0 STD IN, 1 STD OUT, 2 STD ERROR
echo $log END
echo
fi
done
#END
ls -l auth -> blank file
ls -l maillog -> blank file
#!/bin/bash
mydate=`date +%b\ %d`
myscript=`basename $0`
myscripterrors=$myscript.errors
log1=/var/log/messages
log2=/var/log/maillog
echo $mydate
for log in $log{1,2}
do
if [ -e $log ] && [ -s $log ] # this will be executed if log files log1 or log2 does not exists and the file is not empty. We don't process empty files
then
echo $log BEGIN
grep -E "$mydate" $log 2> $myscripterrors # 0 STD IN, 1 STD OUT, 2 STD ERROR
echo $log END
echo
fi
done
if [ -e $myscripterrors ] && [ ! -s $myscripterrors ]
then
rm -rf $myscripterrors
fi
#END
#!/bin/bash
mydate=`date +%b\ %d`
myscript=`basename $0`
myscripterrors=$myscript.errors
log1=/var/log/messages
log2=/var/log/maillog
log3=/var/log/mysqld
log4=/var/log/secure
log4=/var/log/cron
echo $mydate
for log in $log{1,2,3,4,5}
do
if [ -e $log ] && [ -s $log ] # this will be executed if log files log1 or log2 does not exists and the file is not empty. We don't process empty files
then
echo $log BEGIN
grep -E "$mydate" $log 2> $myscripterrors # 0 STD IN, 1 STD OUT, 2 STD ERROR
echo $log END
echo
fi
done
#clean STDERR geenrated file from GREP
if [ -e $myscripterrors ] && [ ! -s $myscripterrors ]
then
rm -rf $myscripterrors
fi
#END
./logabstract.sh >> `date +%F`.logabbstract
No comments:
Post a Comment