Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [[ "$1" != "daily" ]] && [[ "$1" != "hourly" ]]; then
- echo "Usage: ${BASH_SOURCE[0]} <daily|hourly>"
- exit 1
- fi
- awk -v type="$1" '
- function human(size) {
- i=1
- units=" KMGTPEZY";
- while (size >= 1024) {
- size /= 1024;
- i++;
- }
- unit=(i == 1 ? "" : substr(units, i, 1))
- return sprintf("%.2f%sB", size, unit)
- }
- BEGIN {
- ub=0; tb=0; gtu=0; gtm=0; records=0;
- date=""
- system("hostname")
- print "--------------------------------------------------"
- printf "%*s %10s %10s %10s\n", type=="daily" ? 10 : 16, "Date", "Unique", "Meta", "Total"
- print "--------------------------------------------------"
- }
- NR == 1 {
- date=$1
- ub=strtonum($2)
- tb=strtonum($3)
- }
- NR != 1 {
- ue=strtonum($2)
- te=strtonum($3)
- u=ue-ub;
- if (tb != 0) m=(te-tb)/65536*24;
- else m=0;
- gtu+=u; gtm+=m; records+=1;
- printf "%s %10s %10s %10s\n", substr(date, 1, type=="daily" ? 10 : 16), human(u), human(m), human(u+m)
- ub=ue; tb=te;
- date=$1
- }
- END {
- print "=================================================="
- printf "%*s %10s %10s %10s\n", (type=="daily" ? 10 : 16), "Total:", human(gtu), human(gtm), human(gtu+gtm)
- }
- ' /root/ddfs-uniq-$1.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement