我编写了一个脚本来获取用户的浏览器版本,但我需要清理输出。该脚本的作用是查看 @ 和 IE8 的 apache 日志,然后通过电子邮件将信息发送给我。我遇到的问题是输出,因为当 grep 找到电子邮件地址和 IE8 时,它给了我完整的输出 - 即 /page/code/user@foobar.com/home.php 而我正在寻找的输出只是电子邮件地址,并且每天只记录一次此信息:
例子:
用户@foobar IE8
谢谢
#!/bin/bash
#Setting date and time (x and y and z aren't being used at the moment)
x="$(date +'%d/%b/%Y')"
y="$(date +'%T')"
z="$(date +'%T' | awk 'BEGIN { FS =":"} ; {print $1}')"
#Human readable for email title
emaildate=$(date +"%d%b%Y--Hour--%H")
#Setting date and time for grep and filename
beta="$(date +'%d/%b/%Y:%H')"
sigma="$(date +'%d-%b-%Y-%H')"
#CurrentAccess logs
log='/var/logs/access.log'
#Set saved log location
newlogs=/home/user/Scripts/browser/logs
#Prefrom the grep for the current day
grep @ $log | grep $beta | awk 'BEGIN { FS = " " } ; { print $7 }' | sort -u >> $newlogs/broswerusage"$sigma".txt
mail -s "IE8 usage for $emaildate" user@exmaple.com < $newlogs/broswernusage"$sigma".txt