52 lines
1.8 KiB
Fish
Executable File
52 lines
1.8 KiB
Fish
Executable File
#!/usr/bin/env fish
|
|
|
|
set access_log ~/.temp.log
|
|
cat "/home/gemini/access.log" > $access_log
|
|
|
|
set day (date +"%d")
|
|
set month (date +"%m")
|
|
set year (date +"%Y")
|
|
|
|
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
|
|
|
|
# missing cal command so next line won't run
|
|
# set total_days_prev_month (cal $pmonth $pyear |egrep -v [a-z] |wc -w)
|
|
#
|
|
# so here is my workaround
|
|
# fish is 1-indexed
|
|
#
|
|
# 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]
|
|
|
|
# loop through days of prev month starting on same day of month
|
|
for day_counter in (seq $day $total_days_prev_month)
|
|
set user_subtotal (grep $USER $access_log | grep (date --date=$pyear-$pmonth-$day_counter +"%Y-%m-%d" ) | wc -l)
|
|
set entire_subtotal (grep (date --date=$pyear-$pmonth-$day_counter +"%Y-%m-%d" ) $access_log | 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 user_subtotal2 (grep $USER $access_log | grep (date +"%m") | wc -l)
|
|
set entire_subtotal2 ( grep (date +"%m") $access_log | wc -l)
|
|
|
|
echo "Gemlog stats for Ctrl-C Club"
|
|
echo "Views today: " ( grep (date +"%Y-%m-%d") $access_log | wc -l )
|
|
echo "Views past month: " (math $entire_subtotal + $entire_subtotal2)
|
|
echo "Views for all time: " (cat $access_log | wc -l) # just the total number of lines of the log
|
|
|
|
echo -e "\nGemlog stats for ~$USER"
|
|
echo "Views today: " (grep $USER $access_log | grep (date +"%Y-%m-%d") | wc -l)
|
|
echo "Views past month: " (math $user_subtotal + $user_subtotal2)
|
|
echo "Views for all time: " (grep $USER $access_log | wc -l)
|
|
|
|
|
|
rm -f $access_log
|