#!/bin/bash # ========== # $File: //guest/amo/scripts/uc.sh $ # $Revision: #1 $ # $Change: 24793 $ # # $Author: amo $ # $DateTimeTZ: 2018/10/25 06:33:51 -0700 PDT $ # ---------- # An attempt to count the number of users in the system each day, based on spec-depot entries for 'user'. # Requires four parameters - P4PORT, a depot path (probably '//spec/user/...') and two dates in the format 'yyyy/mm/dd'. # # Drops out on failing one of various checks # 1. wrong number of parameters # 2. no 'p4' available # 3. no valid login ticket # 4. can't find path specified # 5. log file already exists (might not want to overwrite the content) # 6. startdate invalid # 7. enddate invalid # # Once through, the script runs 'p4 files' against the user-specs in the spec depot. # It reports the user count on a given day (specs not deleted), then number added, edited and deleted. # # ========== # expecting four parameters - P4PORT, a depot path and two dates if [ "$#" -ne 4 ]; then printf "Usage: %s %s %s %s %s\n%s\n%s\n" $0 "P4PORT" "depotpath" "date" "date" "depot: //spec/user/..." "date format is 'yyyy/mm/dd'" exit 1 fi # check there is a 'p4' available p4cli=`which p4` if [ "$?" -ne 0 ]; then printf "%s: 'p4' client not found.\n" $0 exit 2 fi # check there's a valid connection (looks for ticket) $p4cli login -s > /dev/null 2>&1 if [ $? -ne 0 ]; then printf "%s: 'p4' not logged in or no connection available.\n" $0 exit 3 fi p4cmd="$p4cli -p $1 files" depotpath=$2 # check if the path exists/can be accessed $p4cmd -m1 $depotpath > /dev/null if [ $? -ne 0 ]; then printf "%s: path %s does not exist or is not accessible.\n" $0 $depotpath exit 4 fi of=$0.log if [ -f $of ]; then printf "%s: log file '%s' already exists. Not continuing.\n" $0 $of exit 5 fi sd=$3 ed=$4 startdate=$( date -d $sd +"%Y/%m/%d" ) || exit 6 enddate=$( date -d $ed +"%Y/%m/%d" ) || exit 7 d="$startdate" D=$( date -d "$d + 1 day" +"%Y/%m/%d" ) printf "$0: counting user changes in the spec depot" > $of printf "Parameters: $1 $2 $3 $4" >> $of printf "Date range: %s - %s\n" $startdate $enddate >> $of while [ "$( date -d "$d" +%Y%m%d)" -le "$( date -d "$enddate" +%Y%m%d)" ]; do uc=$( $p4cmd files $depotpath@$d 2>/dev/null | grep -v "delete default change" | wc -l ) ua=$( $p4cmd files $depotpath@$d,@$D 2>/dev/null | grep "add default change" | wc -l ) ue=$( $p4cmd files $depotpath@$d,@$D 2>/dev/null | grep "edit default change" | wc -l ) ud=$( $p4cmd files $depotpath@$d,@$D 2>/dev/null | grep "delete default change" | wc -l ) printf "%s-%s\tc: %d\ta: %d\te: %d\td: %d\n" $d $D $uc $ua $ue $ud >> $of d=$D D=$( date -d "$d + 1 day" +"%Y/%m/%d" ) done printf "$0: end of count" >> $of
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 24796 | Adam Morriss | renaming the file | ||
#3 | 24795 | Adam Morriss |
Minor adjustments. * Improved the filename to which the output is written. * Switched the write-to-file mechanism. * Corrected the counting commands (an additional 'files' was mistakenly left behind in an earlier tidy-up). |
||
#2 | 24794 | Adam Morriss | minor update - added newline | ||
#1 | 24793 | Adam Morriss | A user-counting script |