Note: right now the auth.log example doesn't work properly. I also plan to code in multiple search terms.
#!/bin/bash
chkroot && [[ $? = 0 ]] || exit 1
logpath='/var/log/'
alllogs=`ls $logpath | grep 'log$'`
clear
for i in $alllogs; do
#special log cases
case $i in
"Xorg.0.log")
search_term="(EE)"
;;
"auth.log")
search_term='authentication failure'
;;
*)
search_term="error"
esac
num_errors=`cat $logpath$i | grep -c "$search_term"`
if [[ "$num_errors" -gt "0" ]]; then
echo -e "\033[1;31m$i\033[0m"
echo " :: found $num_errors instances of '$search_term', expand? [y/N]"
read choice
if [[ $choice = ['y','Y'] ]]; then
cat $logpath$i | grep $search_term | less
fi
else
echo -e "\033[1;34m$i\033[0m"
echo " :: clean"
echo
fi
done
exit 0
chkroot && [[ $? = 0 ]] || exit 1
logpath='/var/log/'
alllogs=`ls $logpath | grep 'log$'`
clear
for i in $alllogs; do
#special log cases
case $i in
"Xorg.0.log")
search_term="(EE)"
;;
"auth.log")
search_term='authentication failure'
;;
*)
search_term="error"
esac
num_errors=`cat $logpath$i | grep -c "$search_term"`
if [[ "$num_errors" -gt "0" ]]; then
echo -e "\033[1;31m$i\033[0m"
echo " :: found $num_errors instances of '$search_term', expand? [y/N]"
read choice
if [[ $choice = ['y','Y'] ]]; then
cat $logpath$i | grep $search_term | less
fi
else
echo -e "\033[1;34m$i\033[0m"
echo " :: clean"
echo
fi
done
exit 0
No comments:
Post a Comment