网站日志分析与远程备份脚本详解
1. 理解搜索引擎流量
1.1 脚本目的
分析搜索引擎流量,不仅能了解哪些搜索引擎带来了流量,还能知道通过搜索引擎访问网站的用户输入了哪些关键词。这有助于判断网站是否被搜索引擎正确索引,并为提高网站在搜索引擎中的排名和相关性提供起点。
1.2 代码实现
#!/bin/sh
# searchinfo - Extracts and analyzes search engine traffic indicated in the
# referrer field of a Common Log Format access log.
host="intuitive.com" # change to your domain, as desired
maxmatches=20
count=0
temp="/tmp/$(basename $0).$$"
trap "/bin/rm -f $temp" 0
if [ $# -eq 0 ] ; then
echo "Usage: $(basename $0) logfile" >&2
exit 1
fi
if [ ! -r "$1" ] ; then
echo "Error: can't open file $1 for analysis." >&2
exit 1
fi
for URL in $(awk '{ if (length($11) > 4) { print $11 } }' "$1" | \
grep -vE "(/www.$host|/$host)" | gre