update gemstats.fish
This commit is contained in:
parent
3b1aa02b41
commit
87646dfc51
|
@ -1,17 +1,42 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
# counts total hits on my gemlog based on access log file, removing ip address
|
||||
set access_log ~/code/gemstats/temp.log
|
||||
cat "/home/gemini/access.log" > $access_log
|
||||
|
||||
# lettuce feb 2021
|
||||
#cc0 public domain, no rights reserved
|
||||
set day (date +"%d")
|
||||
set month (date +"%m")
|
||||
set year (date +"%Y")
|
||||
|
||||
echo "~lettuce"
|
||||
echo "total hits alltime: "
|
||||
grep lettuce /home/gemini/access.log | grep -v "69.120.239.191" | wc -l
|
||||
if test $month -eq 1
|
||||
# check whether current month is jan
|
||||
set pmonth 12 #set to dec
|
||||
set pyear (math (date +"%Y") - 1) #set to previous year
|
||||
else
|
||||
set pmonth (math $month - 1) #set to prev month
|
||||
set pyear $year
|
||||
end
|
||||
|
||||
echo "total hits current month: "
|
||||
grep lettuce /home/gemini/access.log | grep (date +"%m") | wc -l
|
||||
# set total_days_prev_month (cal $pmonth $pyear |egrep -v [a-z] |wc -w)
|
||||
#
|
||||
# we don't have cal installed
|
||||
# so here is my workaround
|
||||
#
|
||||
# J F M A M J J A S O N D
|
||||
set month_days 31 28 31 30 31 30 31 31 30 31 30 31
|
||||
set total_days_prev_month $month_days[$pmonth]
|
||||
|
||||
echo "total hits today: "
|
||||
grep lettuce /home/gemini/access.log | grep (date +"%Y-%m-%d") | wc -l
|
||||
# loop through days of prev month starting on same day of month
|
||||
for day_counter in (seq $day $total_days_prev_month)
|
||||
set subtotal (grep $USER $access_log | grep (date --date=$pyear-$pmonth-$day_counter +"%Y-%m-%d" ) | wc -l)
|
||||
end
|
||||
|
||||
# check access log for current month
|
||||
# easier since we don't need to weed out people viewing the gemlog AFTER our date (unless there is time travel)
|
||||
set subtotal2 (grep $USER $access_log | grep (date +"%m") | wc -l)
|
||||
|
||||
echo "Gemlog stats for ~$USER"
|
||||
echo "Views today: " (grep $USER $access_log | grep (date +"%Y-%m-%d") | wc -l)
|
||||
echo "Views past month: " (math $subtotal + $subtotal2)
|
||||
echo "Views for all time: " (grep $USER $access_log | grep -v "69.120.239.191" | wc -l)
|
||||
|
||||
rm $access_log
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
set access_log "/home/lettuce/code/gemstats/temp.log"
|
||||
cat "/home/gemini/access.log" > $access_log
|
||||
|
||||
set day (date +"%d")
|
||||
echo "current day :" $day
|
||||
|
||||
set month (date +"%m")
|
||||
echo "current month:" $month
|
||||
|
||||
set year (date +"%Y")
|
||||
echo "current year:" $year
|
||||
|
||||
if test $month -eq 1
|
||||
# check whether current month is jan
|
||||
set pmonth 12 #set to dec
|
||||
set pyear (math (date +"%Y") - 1) #set to previous year
|
||||
else
|
||||
set pmonth (math $month - 1) #set to prev month
|
||||
set pyear $year
|
||||
end
|
||||
|
||||
echo "previous month:" $pmonth
|
||||
echo "previous month's year" $pyear
|
||||
|
||||
# set total_days_prev_month (cal $pmonth $pyear |egrep -v [a-z] |wc -w)
|
||||
#
|
||||
# we don't have cal installed
|
||||
# so here is my workaround
|
||||
#
|
||||
# J F M A M J J A S O N D
|
||||
set month_days 31 28 31 30 31 30 31 31 30 31 30 31
|
||||
set total_days_prev_month $month_days[$pmonth]
|
||||
echo "# days last month:" $total_days_prev_month
|
||||
|
||||
# loop through days of prev month starting on same day of month
|
||||
for day_counter in (seq $d $total_days_prev_month)
|
||||
set subtotal (grep lettuce $access_log | grep (date --date=$pyear-$pmonth-$day_counter) | wc -l)
|
||||
end
|
||||
|
||||
echo "subtotal: " $subtotal
|
||||
|
||||
# loop through days of current month
|
||||
set subtotal2 (grep lettuce $access_log | grep (date +"%m") | wc -l)
|
||||
|
||||
echo "grand total past month: " (math $subtotal + $subtotal2)
|
||||
|
||||
rm $access_log
|
Loading…
Reference in New Issue