WHATSNEW: Start release notes for 3.6.0.
[Samba.git] / examples / ad-bench / utils.sh
blob89da09cb1f252c0f641b0a392c124b8c3d52260b
1 #!/bin/bash
2 # AD-Bench utility functions
4 # Copyright (C) 2009 Kai Blin <kai@samba.org>
6 # This file is part of AD-Bench, an Active Directory benchmark tool
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.
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.
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/>.
21 source `dirname $0`/settings.sh
23 start_timer () {
24 START_TIME=$( ${DATE} ${DATE_FORMATSTR} )
25 echo "$START_TIME"
28 stop_timer () {
29 STOP_TIME=$( ${DATE} ${DATE_FORMATSTR} )
30 echo "$STOP_TIME"
33 total_time () {
34 START_TIME=$1
35 END_TIME=$2
36 TOTAL_TIME=$( echo "scale=9;$STOP_TIME - $START_TIME" | ${BC} )
37 echo "$TOTAL_TIME"
40 iterations_per_minute () {
41 START_TIME=$1
42 STOP_TIME=$2
43 TOTAL_RUNS=$3
45 TOTAL_TIME=$( total_time $START_TIME $STOP_TIME )
47 ITER_PER_MIN=$( echo "scale=2; 60 * $TOTAL_RUNS / $TOTAL_TIME" | ${BC} )
48 echo "$ITER_PER_MIN"
51 get_principal () {
52 PRINCIPAL=$( echo $1 | ${SED} -e "s/\(.*\)%.*/\1/" )
53 echo "$PRINCIPAL"
56 get_password () {
57 PASSWORD=$( echo $1 | ${SED} -e "s/.*%\(.*\)/\1/" )
58 echo "$PASSWORD"
61 get_realm () {
62 REALM=$( echo $1 | ${SED} -e "s/.*@\(.*\)%.*/\1/" )
63 echo "$REALM"
66 get_nt_dom () {
67 NT_DOM=$( echo $1 | ${SED} -e "s/.*@\([A-Z1-9-]*\)\..*/\1/" )
68 echo "$NT_DOM"
71 set_krb_env () {
72 OLD_KRB5CCNAME="${KRB5CCNAME}"
73 KRB5CCNAME="${NEW_KRB5CCNAME}"
74 export KRB5CCNAME
77 restore_krb_env () {
78 KRB5CCNAME="${OLD_KRB5CCNAME}"
79 export KRB5CCNAME
82 setup_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}"
91 write_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
100 call_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
111 pad_number () {
112 NUMBER=$1
113 DIGITS=$2
114 PADDED_NO=$(printf "%0${DIGITS}d" $NUMBER)
115 echo $PADDED_NO