[Dxspider-support] Top users command ?

Libor Berka ok2pen at seznam.cz
Sun Mar 26 15:34:04 BST 2023


Good script, thanks Niels
73
Libor

On 3/26/23 10:50, Niels PD9Q via Dxspider-support wrote:
> #!/bin/bash
> ts=$(date +%s%N)
> # Path to the log dir
> path=/spider/local_data/log
> # Get Month and Year.
> month=$(date +%m)
> year=$(date +%Y)
> # Get the log file.
> file="$path"/"$year"/"$month".dat
> if [ -f "$file" ]; then
>     a="$path"/"$year"/"$month".dat
> else
>     echo "$file does not exist. Error, check the path."
> fi
> # Get some info about the log file
> size=$(du -sh "$path"/"$year"/"$month".dat | awk '{ print $1 }')
> line=$(wc -l "$a")
> # Get the connected from.
> b=$(sed -n '/connected from/p' "$a")
> # Remove some mess.
> c=$(echo "$b" | sed -e '/\>^DXProt^\</d' -e 's/\>^DXCommand^\</ /g')
> # Remove connecteds from localhost (Nobody have to see that i`m 
> connecting 1000 times a day) Remove sk1/sk0.
> d=$(echo "$c" | sed -e '/127.0.0.1/d' -e '/SK0MMR/d' -e '/SK1MMR/d' -e 
> '/PD9Q/d')
> # First connect from call... uniq on the second column.
> e=$(echo "$d" | awk -F '[ .]' '!uniq[$2]++')
> # Last connect from call sort bottom to top / uniq on the second column.
> f=$(echo "$d" | sort -t: -k 1nr,1 | awk -F '[ .]' '!uniq[$2]++')
> # Change the epoch time to reable text (can find any good option in 
> bash so perl it is).
> g=$(echo "$e" | perl -pe 's/(\d+)/localtime($1)/e')
> h=$(echo "$f" | perl -pe 's/(\d+)/localtime($1)/e')
> # Echo to a file, need it to compare.
> echo "$g" > first
> echo "$h" > last
> grep -vxFf first last >last.tmp && mv last.tmp last
> i=$(cat first)
> j=$(cat last )
> # ** Count times connected
> # Get only the calls
> m=$(echo "$d" | awk -F' ' '{ print $2}')
> #
> count_total=$(echo "$m" | wc -l)
> # Count the uniq calls, add the times off connection and sort
> n=$(echo "$m" | awk -- '{for (i = 1; i <= NF; i++) wc[$i] +=1}; END 
> {for (w in wc) print w, wc[w]}' | sort)
> count_call=$(echo "$n" | wc -l)
> # Add line number
> o=$(echo "$n" |awk -v ln=1 '{print ln++  " "  $0 }')
> # Add tab between numbers and words
> p=$(echo "$o" | awk -v OFS='\t\t' '{ print $1, $2, $3 }')
>
> div================================================================
> div=$div$div
>
> width=85
>
> printf "\n** Output Generated on %(%m-%d-%Y %H:%M:%S)T\n" $(date +%s)
> printf "** Log file : "$a"\n"
> printf "** Files size : "$size"\n"
> printf "** Lines in the log file : "$line""
> printf "\n** Total of inbound connects : "$count_total""
> printf "\n** Total users : "$count_call"\n"
> printf "** Connected Stations over a month\n"
> printf "%$width.${width}s\n" "$div"
> printf "$i\n" | column -t
> printf "%$width.${width}s\n" "$div"
> printf "** End Connected Stations\n\n"
>
> printf "** Last Connected Stations - Return Connects\n"
> printf "%$width.${width}s\n" "$div"
> printf "$j\n" | column -t
> printf "%$width.${width}s\n" "$div"
> printf "** End last Connected Stations\n"
>
>
> header="\n%-0s %5s %11s\n"
> width=38
> printf "$header" "Nr" "Call" "Times"
> printf "$p\n" | column -t
> echo "Script Runtime $((($(date +%s%N) - $ts)/1000000))ms"
>
>  73 Niels PD9Q / PI1LAP-1
>
> Op 26-3-2023 om 05:32 schreef Tim Tuck via Dxspider-support:
>> Hi all,
>>
>> I want to turn on registration on my node but I'd like to 
>> pre-register my top users in the process to minimise any pain.
>>
>> The question then is... who are my top users ?
>>
>> I couldn't find a command to show me any form of database of who has 
>> connected to and used my node over the past month other than parsing 
>> the log files for the connected statements.
>>
>> So before I go do some scripting around the log files I thought I'd 
>> ask if anyone has done this and can share  😄
>>
>> Of course I could be missing something obvious so I stand by for a 
>> face palm moment!
>>
>> thanks
>>
>> Tim
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.tobit.co.uk/pipermail/dxspider-support/attachments/20230326/4ea01178/attachment.htm>


More information about the Dxspider-support mailing list