#! /usr/local/bin/zsh # # this file: # https://dataswamp.org/~incal/blog/meta/piles # # current output: [DNC] # https://dataswamp.org/~incal/blog/hits.txt log=/var/www/logs/access-${USER}.log data_files_path=${HOME}/public_html/blog data_files_name=hits data_files_type=txt data=${data_files_path}/${data_files_name}.${data_files_type} data_old=${data_files_path}/${data_files_name}-old.${data_files_type} p='' pages=( 'blog/index.html' 'box-10/marco-antonio-barrera.html' 'box-10/top-10-modern-boxers.html' 'climbing-gear/climbing-gear.html' 'climbing-gear/harness.html' 'tree-house/blodstensskogen-nature-reserve.html' 'tree-house/summer-2021.html' 'tree-house/tradkojan-i-blodstensskogen.html' 'tree-house/tree-house-pulley.html' 'tree-house/tree-house-rooftop.html' 'tree-house/tree-house.html' 'tree-house/winter-video.html' 'ut/ut.png' ) local -a name local short_name local hits local hits_old local diff local diff_str=" " local total=0 local total_old=0 local total_diff local total_diff_str # hit count to be done again, # that means current data is now old data if [[ -f $data ]]; then cp -f $data $data_old fi local pad_col=39 local pad_size for p in $pages; do name=(${(s:/:)p}) short_name=$name[2] hits=$(cut -d ' ' -f 2,8 $log | grep $p | sort | cut -d ' ' -f 1 | uniq -c | wc -l) total=$(( $total + $hits )) if [[ -f $data_old ]]; then hits_old=$(grep $short_name $data_old | tr -s ' ' | cut -d ' ' -f 2) total_old=$(( $total_old + $hits_old )) diff=$(( $hits - $hits_old )) if [[ $diff > 0 ]]; then diff_str="+$diff" pad_size=$(( $pad_col - ${#short_name} )) diff_str=${(l:$pad_size:: :)diff_str} else diff_str="" fi fi echo "$hits ${short_name}${diff_str}" done > $data sort -r $data | tee $data total_diff=$(( $total - $total_old )) if [[ $total_diff > 0 ]]; then total_diff_str="[+$total_diff]" else total_diff_str="[±0]" fi echo " -----\n $total $total_diff_str" | tee -a $data