本人只是一枚中职生小白,在管理学校的网站,这些脚本都是我为了管理这些网站自己写的,请高手不要见笑,请多指点指点,谢谢。如果没有在代码中体现的变量,已经被我定义成了环境变量。
请说明,我对网页一点兴趣也没有,也不会。就草草了事吧,能用就行了。
以下是脚本部分
#!/bin/bash
LOGNAME=$(date -d yesterday --rfc-3339=date)
LOGDIR=/home/log/$LOGNAME/
mkdir -p $LOGDIR
HTTPACC=$(date -d yesterday +%d/%b/20%y)
GREPNAME=$(date -d yesterday |awk '{print $2,$3}')
HTMLNAME=$LOGDIR/$(date -d yesterday --rfc-3339=date).html
chattr -a /home/log
cat /var/log/messages |grep "$GREPNAME" >${LOGDIR}/${LOGNAME}mess.log
cat /var/log/xferlog |grep "$GREPNAME" >${LOGDIR}/${LOGNAME}ftp.log
cat /var/log/httpd/access_log |grep $HTTPACC >${LOGDIR}/${LOGNAME}http_acc.log
cat /var/log/httpd/error_log |grep "$GREPNAME" >${LOGDIR}/${LOGNAME}http_error.log
echo "<a href="$LOGNAME/$LOGNAME.html">$LOGNAME</a> " >>/home/log/index.html
echo "<title>$LOGNAME</title>" >$HTMLNAME
cat top.html >>$HTMLNAME
T=(http连接日志 http错误日志 ftp日志 系统信息)
N=(${LOGNAME}http_acc.log ${LOGNAME}http_error.log ${LOGNAME}ftp.log ${LOGNAME}mess.log)
for ((i=0; i<=3; i=i+1))
do
MAIN="<div id="I${i}" class="main">"
XZ="<a href="${N[i]}">下载日志全文</a>"
echo "${MAIN}<div class="t">${T[i]}$XZ</div><div class='m'>" >>$HTMLNAME
# echo "<div class="t">${T[i]}$XZ</div>" >>index.html
# echo '<div class='m'>' >>index.html
head -100 $LOGDIR/${N[i]} |nl >>$HTMLNAME
echo '</div></div>' >>$HTMLNAME
done
HTMLIP=$(cat ${LOGDIR}/${LOGNAME}http_acc.log |awk '{print $1}' |grep -v ":" |sort -u |wc |awk '{print $1}')
FTPIPS=$(cat ${LOGDIR}/${LOGNAME}ftp.log |awk '{print $7}' |sort -u|wc|awk '{print $1}')
echo "<div id="I4" class="main"><div class="t">访问统计</div><div class='m'>" >>$HTMLNAME
echo "日网页IP访问数:${HTMLIP}<br>日ftp访问数:${FTPIPS}<br>登录过ftp的ip:" >>$HTMLNAME
cat ${LOGDIR}/${LOGNAME}ftp.log |awk '{print $7}' |sort -u >>$HTMLNAME
echo "服务器本日登录IP:">>$HTMLNAME
last | grep "`date -d yesterday|awk '$3<10{print $1,$2," "$3} $3>=10{print $1,$2,$3}' `" >>$HTMLNAME
以下是网页头部分,关键是来定网站外形的:************
<a name="top" id="top"></a><!doctype html><html><head><meta charset="utf-8"><style type="text/css">* {margin: 0px;padding: 0px;line-height: 150%;}body{background-color: #F3F3F3;}nav {background-color: #0072C6;}nav ul{height: 100px;margin-right: auto;margin-left: auto;}nav ul li {display: block;height: 100px;width: 20%;list-style-type: none;float: left;}nav ul li a {font-size: 36px;color: #FFF;width: 100%;text-align: center;display: block;height: 60px;padding-top: 30px;text-decoration: none;}nav ul li:hover {background-color: #5133AB;}nav ul li a:hover {background-color: #005EA5;}.main {margin: 10px;border: 1px solid #0072C6;background-color: #FFF;}.t {font-size: 24px;font-weight: bolder;color: #003;margin: 5px;}.t a{float: right;}.m {margin-right: 5px;margin-left: 5px;margin-bottom: 5px;font-size: 18px;color: #000057;word-wrap: break-word; white-space: pre-wrap;white-space: -moz-pre-wrap;}</style></head><body><nav><ul> <li><a href="#I0">http连接日志</a></li> <li><a href="#I1">http错误日志</a></li> <li><a href="#I2">ftp日志</a></li> <li><a href="#I3">系统信息</a></li> <li><a href="#I4">访问统计</a></li></ul></nav><div style="position:fixed;width:0px;height:30px;text-align:center;top:0px"><a href="#top" target="_self"><b>↑</b></a></div>
以下是我的日志目录的根目录*****
下面是日志网站的首页
随便点个进去