source: vendor/3.6.23/examples/ad-bench/utils.sh

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 2.6 KB
Line 
1#!/bin/bash
2# AD-Bench utility functions
3#
4# Copyright (C) 2009 Kai Blin <kai@samba.org>
5#
6# This file is part of AD-Bench, an Active Directory benchmark tool
7#
8# AD-Bench is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# AD-Bench is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with AD-Bench. If not, see <http://www.gnu.org/licenses/>.
20
21source `dirname $0`/settings.sh
22
23start_timer () {
24 START_TIME=$( ${DATE} ${DATE_FORMATSTR} )
25 echo "$START_TIME"
26}
27
28stop_timer () {
29 STOP_TIME=$( ${DATE} ${DATE_FORMATSTR} )
30 echo "$STOP_TIME"
31}
32
33total_time () {
34 START_TIME=$1
35 END_TIME=$2
36 TOTAL_TIME=$( echo "scale=9;$STOP_TIME - $START_TIME" | ${BC} )
37 echo "$TOTAL_TIME"
38}
39
40iterations_per_minute () {
41 START_TIME=$1
42 STOP_TIME=$2
43 TOTAL_RUNS=$3
44
45 TOTAL_TIME=$( total_time $START_TIME $STOP_TIME )
46
47 ITER_PER_MIN=$( echo "scale=2; 60 * $TOTAL_RUNS / $TOTAL_TIME" | ${BC} )
48 echo "$ITER_PER_MIN"
49}
50
51get_principal () {
52 PRINCIPAL=$( echo $1 | ${SED} -e "s/\(.*\)%.*/\1/" )
53 echo "$PRINCIPAL"
54}
55
56get_password () {
57 PASSWORD=$( echo $1 | ${SED} -e "s/.*%\(.*\)/\1/" )
58 echo "$PASSWORD"
59}
60
61get_realm () {
62 REALM=$( echo $1 | ${SED} -e "s/.*@\(.*\)%.*/\1/" )
63 echo "$REALM"
64}
65
66get_nt_dom () {
67 NT_DOM=$( echo $1 | ${SED} -e "s/.*@\([A-Z1-9-]*\)\..*/\1/" )
68 echo "$NT_DOM"
69}
70
71set_krb_env () {
72 OLD_KRB5CCNAME="${KRB5CCNAME}"
73 KRB5CCNAME="${NEW_KRB5CCNAME}"
74 export KRB5CCNAME
75}
76
77restore_krb_env () {
78 KRB5CCNAME="${OLD_KRB5CCNAME}"
79 export KRB5CCNAME
80}
81
82setup_kinit () {
83 ${KINIT} --invalid 2>&1 | grep -q "password-file"
84 if [ $? -eq 0 ]; then
85 KINIT="${KINIT} ${KINIT_PARAM_OLD}"
86 else
87 KINIT="${KINIT} ${KINIT_PARAM_NEW}"
88 fi
89}
90
91write_configfile () {
92 REALM=$1
93 NT_DOM=$2
94 echo -e "[global]" > $CONFIG_FILE
95 echo -e "\trealm = $REALM" >> $CONFIG_FILE
96 echo -e "\tworkgroup = $NT_DOM" >> $CONFIG_FILE
97 echo -e "\tsecurity = ADS" >> $CONFIG_FILE
98}
99
100call_kinit () {
101 PRINCIPAL=$1
102 PASSWORD=$2
103 echo "${PASSWORD}" | ${KINIT} ${PRINCIPAL} > /dev/null
104 RET=$?
105 if [ $RET -ne 0 ]; then
106 echo "kinit returned an error: $RET"
107 exit 1
108 fi
109}
110
111pad_number () {
112 NUMBER=$1
113 DIGITS=$2
114 PADDED_NO=$(printf "%0${DIGITS}d" $NUMBER)
115 echo $PADDED_NO
116}
Note: See TracBrowser for help on using the repository browser.