LOG_DAYS=1
todays_date=`date +%m:%d:%Y`
current_date=`echo $todays_date | sed 's/://g'`
day=`echo $todays_date | cut -f 2 -d ":"| sed 's/^0//g'`
month=`echo $todays_date | cut -f 1 -d ":"| sed 's/^0//g'`
year=`echo $todays_date | cut -f 3 -d ":"`
case $LOG_DAYS in
*[!0-9]* | ???* | 3? | 29) printf -u2 "Invalid input\n" ; exit 2;;
esac
tday=$day
tmonth=$month
tyear=$year
day=$((day - LOG_DAYS))
if (( day <= 0 )) ; then
month=$((month - 1))
if (( month == 0 )) ;then
year=$((year - 1))
month=12
fi
days=`/usr/bin/cal $month $year`
xday=`echo $days | awk '{print $NF}'`
day=$((xday + day))
fi
if (( ${#day} == 2 ));then
day=`echo $day | sed 's/^[1-9]\{1\}/ &/'`
else
day=`echo $day | sed 's/^[1-9]\{1\}/ &/'`
fi
if (( ${#tday} == 2 ));then
tday=`echo $tday | sed 's/^[1-9]\{1\}/ &/'`
else
tday=`echo $tday | sed 's/^[1-9]\{1\}/ &/'`
fi

month=`cal $month $year | head -n 1 | cut -c 4-6`
tmonth=`cal $tmonth $year | head -n 1 | cut -c 4-6`

 

grep -e "$month$day" -e "$tmonth$tday" /var/adm/syslog/syslog.log | grep -v -e "sshd" -e "ftpd" -e "su:" -e "ETDirect" -e "inetd"

posted on 2016-09-08 14:15  zlg88  阅读(528)  评论(0编辑  收藏  举报