/ Published in: Bash

Expand |
Embed | Plain Text
#!/bin/bash #initialize temp files echo "" > topimages.txt echo "" > images.txt echo "" > unique.txt echo "" > all.txt if [ "$1" = "" ]; then echo -e "normally use like this:" echo -e " ./getTopPages.sh $1" echo -e " get all jpg's -- ./getTopPages.sh jpg" echo -e " get everything in photos -- ./getTopPages.sh photos" echo -e "*****" exit fi #live server logfile logfile=/var/log/httpd/... grep $1 $logfile| awk '{print $7}' | sort > all.txt echo found: $(grep '^.*$' all.txt -c) images total... grep $1 $logfile| awk '{print $7}' | sort | uniq > unique.txt echo found: $(grep '^.*$' unique.txt -c) unique images... echo '<images>' > images.txt for i in $( grep '^.*$' unique.txt ); do cnt=$( grep $i all.txt -c ) #add leading zeros if test $cnt -lt 10; then lzcnt=0000$cnt elif test $cnt -lt 100; then lzcnt=000$cnt elif test $cnt -lt 1000; then lzcnt=00$cnt elif test $cnt -lt 10000; then lzcnt=0$cnt elif test $cnt -lt 100000; then lzcnt=$cnt else lzcnt=$cnt fi echo '<image count="'$lzcnt'" src="'$i'" />' >> images.txt done sort images.txt -r -k17 > topimages.xml echo '</images>' >> topimages.xml echo removing temp files... rm images.txt rm unique.txt rm all.txt rm topimages.txt
You need to login to post a comment.