#!/usr/bin/perl -w # #******************************************************************************* # #Copyright (c) 2009, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #******************************************************************************* # #Author: Stephen Moon # #Date: July 8, 2009 #Program: Returns the maximum values of MaxResults, MaxScanRows, MaxLockTime and # Timeout fields for all the groups that the specified user belongs to. # #******************************************************************************* use strict; my $debug = 0; #change this to 1 if you want debug output my $argc = @ARGV; my $grpHashRef = {}; #anonymous hashRef for groups the user belongs to my $eachGrp = ""; if($argc != 1) { die "Usage: getMaxLimit.pl \n"; } #my $p4 = "p4 -u bruno -c bruno_ws -p 20082"; my $p4 = "p4"; #descriptor for group names which the user belongs to open(EACHGRP,"$p4 groups $ARGV[0] |") or die "Unable to open $ARGV[0] stream: $!\n"; while() { chomp; $eachGrp = $_; #display content for each group spec. foreach(`$p4 group -o $eachGrp`) { if (/^(\w+):\s+(\w+)$/) { if($1 ne "Group") { $grpHashRef->{$eachGrp}{$1} = $2; #Max* and Timeout keys and values for each group } } } } my $maxHashRef = {}; #anonymous hash for the maximum Max* and Timeout values out of all the groups #that the user belongs to foreach my $grpName (keys %$grpHashRef) { foreach my $field (keys %{$grpHashRef->{$grpName}}) { &getMax($maxHashRef,$grpName,$field,$grpHashRef->{$grpName}{$field}); } } #displays the maximum values for each Max* and Timeout settings out of all the groups that the user #belongs to foreach my $eachField (sort keys %$maxHashRef) { printf "%12s for %5s is %3s\n", $eachField ,$ARGV[0] ,$maxHashRef->{$eachField}{'max'}; } #returns the maximum Max* and Timeout from all the groups that the user belongs to sub getMax { my $maxHashRef = shift; my $grpName = shift; my $field = shift; my $value = shift; if($debug == 1) { print "group: $grpName => key: $field, value: $value\n"; } if (!defined($maxHashRef->{$field}{'max'})) { $maxHashRef->{$field}{'max'} = $value; } if ($value =~ /\D+/ && $value =~ /unlimited/) { $maxHashRef->{$field}{'max'} = $value; } elsif ($value =~ /\d+/ && $maxHashRef->{$field}{'max'} =~ /\d+/) { if($value > $maxHashRef->{$field}{'max'}) { $maxHashRef->{$field}{'max'} = $value; } } }