countclients.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #!/bin/ksh
  2. SCRIPT_VERSION="19.1"
  3. SCRIPT_NAME=${0}
  4. ################################################################################
  5. #
  6. # tuxcredentialValidation - function to check the user running the script and display
  7. # the appropriate messages.
  8. tuxcredentialValidation () {
  9. # use whoami to get user; helps in su and sudo instances; works across platforms.
  10. # if whoami not found default to $LOGNAME
  11. USER_ID_CMD=`type whoami &>/dev/null && echo "Found" || echo "NotFound"`
  12. if [ "$USER_ID_CMD" = "Found" ] ; then
  13. USR_ID=`whoami`
  14. else
  15. if [ "$OS_NAME" = "SunOS" ] ; then
  16. if [ -x /usr/ucb/whoami ] ; then
  17. USR_ID=`/usr/ucb/whoami`
  18. fi
  19. else
  20. USR_ID=$LOGNAME
  21. fi
  22. fi
  23. SCRIPT_USER=$USR_ID
  24. TUXDIRUSER=`ls -ld ${TUXDIR} | awk 'NR==1 {print $3}'`
  25. if [ "${SCRIPT_USER}" != "root" -o "${SCRIPT_USER}" != "${TUXDIRUSER}" ] ; then
  26. $ECHO_COUNTCLIENT "\nCurrent user "${SCRIPT_USER}" is not the owner of the Oracle Tuxedo software installation on this environment!"
  27. $ECHO_COUNTCLIENT "If you’re sure that the current user "${SCRIPT_USER}" is the owner of the Oracle Tuxedo software installation on this environment, continue with yes(y), otherwise select No(n) and please review the examples in the instructions document to see how to start the scripts with a user that has sufficient privileges."
  28. $ECHO_COUNTCLIENT "Running the Collection Script with insufficient privileges may have a significant impact on the quality of the data and information collected from this environment. Due to this, Oracle may have to get back to you and ask for additional items, or to execute again."
  29. ANSWER=
  30. while [ -z "${ANSWER}" ]
  31. do
  32. $ECHO_COUNTCLIENT "\nPlease choose an Y to continue or N to quit:"
  33. read ANSWER
  34. #
  35. # Act according to the user's response.
  36. #
  37. case "${ANSWER}" in
  38. Y|y) ANSWER=y
  39. ;;
  40. N|n) ANSWER=n
  41. break # break out of the loop
  42. ;;
  43. #
  44. # An invalid choice was entered, reprompt.
  45. #
  46. *) ANSWER=
  47. ;;
  48. esac
  49. done
  50. if [ "${ANSWER}" = "n" ] ; then
  51. $ECHO_COUNTCLIENT "\nUser stopped the the Collection Script." >&2
  52. exit 0
  53. fi
  54. fi
  55. }
  56. ##############################################################
  57. # make echo more portable
  58. #
  59. echo_countclients() {
  60. #IFS=" " command
  61. eval 'printf "%b\n" "$*"'
  62. }
  63. # set up $ECHO_COUNTCLIENT
  64. ECHO_COUNTCLIENT="echo_countclients"
  65. ################################################################################
  66. #
  67. # output welcome message.
  68. #
  69. beginMsg()
  70. {
  71. more ../resources/util/license_agreement.txt
  72. ANSWER=
  73. $ECHO_COUNTCLIENT "Accept License Agreement? "
  74. while [ -z "${ANSWER}" ]
  75. do
  76. $ECHO_COUNTCLIENT "$1 [y/n/q]:" >&2
  77. read ANSWER
  78. #
  79. # Act according to the user's response.
  80. #
  81. case "${ANSWER}" in
  82. Y|y)
  83. return 0 # TRUE
  84. ;;
  85. N|n|Q|q)
  86. exit 1 # FALSE
  87. ;;
  88. #
  89. # An invalid choice was entered, reprompt.
  90. #
  91. *) ANSWER=
  92. ;;
  93. esac
  94. done
  95. }
  96. ################################################################################
  97. #
  98. # getconfigmodel() - Get Tuxedo config model
  99. #
  100. getconfigmodel()
  101. {
  102. export FLDTBLDIR32="$TUXDIR/udataobj"
  103. export FIELDTBLS32="tpadm,Usysfl32"
  104. ud32 -C tpsysadm > domain_data.out <<!
  105. SRVCNM .TMIB
  106. TA_OPERATION GET
  107. TA_CLASS T_DOMAIN
  108. !
  109. RETVAL=${?}
  110. if [ ${RETVAL} -ne 0 ]
  111. then
  112. $ECHO_COUNTCLIENT "Could not get the application model\n"
  113. $ECHO_COUNTCLIENT "Please make sure both TUXDIR and TUXCONFIG are set properly.\n"
  114. fi
  115. tux_model=`grep TA_MODEL ./domain_data.out | cut -d' ' -f2`
  116. rm -f ./domain_data.out
  117. }
  118. getMPboottime()
  119. {
  120. #TA_FILTER 33560831 - TA_TIMESTART
  121. #TA_FILTER 33560683 - TA_CURTIME
  122. export FLDTBLDIR32="$TUXDIR/udataobj"
  123. export FIELDTBLS32="tpadm,Usysfl32"
  124. ud32 -C tpsysadm > sttime.out <<!
  125. SRVCNM .TMIB
  126. TA_OPERATION GET
  127. TA_CLASS T_SERVER
  128. TA_SERVERNAME DBBL
  129. TA_FLAGS 65536
  130. TA_FILTER 33560831
  131. !
  132. RETVAL=${?}
  133. if [ ${RETVAL} -ne 0 ]
  134. then
  135. $ECHO_COUNTCLIENT "Could not get application start time\n"
  136. $ECHO_COUNTCLIENT "Please make sure both TUXDIR and TUXCONFIG are set properly.\n"
  137. return
  138. fi
  139. tmptime=`grep TA_TIMESTART ./sttime.out | cut -d' ' -f2`
  140. stime=`$ECHO_COUNTCLIENT "$(($tmptime/((3600*24))))"`
  141. rm -f ./sttime.out
  142. ud32 -C tpsysadm > curtime.out <<!
  143. SRVCNM .TMIB
  144. TA_OPERATION GET
  145. TA_CLASS T_SERVER
  146. TA_SERVERNAME DBBL
  147. TA_FLAGS 65536
  148. TA_FILTER 33560683
  149. !
  150. RETVAL=${?}
  151. if [ ${RETVAL} -ne 0 ]
  152. then
  153. $ECHO_COUNTCLIENT "Could not get application current time\n"
  154. $ECHO_COUNTCLIENT "Please make sure both TUXDIR and TUXCONFIG are set properly.\n"
  155. return
  156. fi
  157. tmptime=`grep TA_CURTIME ./curtime.out | cut -d' ' -f2`
  158. ctime=`$ECHO_COUNTCLIENT "$(($tmptime/((3600*24))))"`
  159. rm -f ./curtime.out
  160. elapsedtime=`$ECHO_COUNTCLIENT "$(($ctime-$stime))"`
  161. $ECHO_COUNTCLIENT "\nThis Server's DBBL started around $elapsedtime day(s) ago\n"
  162. }
  163. getSHMboottime()
  164. {
  165. #TA_FILTER 33560831 - TA_TIMESTART
  166. #TA_FILTER 33560683 - TA_CURTIME
  167. export FLDTBLDIR32="$TUXDIR/udataobj"
  168. export FIELDTBLS32="tpadm,Usysfl32"
  169. ud32 -C tpsysadm > sttime.out <<!
  170. SRVCNM .TMIB
  171. TA_OPERATION GET
  172. TA_CLASS T_SERVER
  173. TA_SERVERNAME BBL
  174. TA_FLAGS 65536
  175. TA_FILTER 33560831
  176. !
  177. RETVAL=${?}
  178. if [ ${RETVAL} -ne 0 ]
  179. then
  180. $ECHO_COUNTCLIENT "Could not get application start time\n"
  181. $ECHO_COUNTCLIENT "Please make sure both TUXDIR and TUXCONFIG are set properly.\n"
  182. return
  183. fi
  184. tmptime=`grep TA_TIMESTART ./sttime.out | cut -d' ' -f2`
  185. stime=`$ECHO_COUNTCLIENT "$(($tmptime/((3600*24))))"`
  186. rm -f ./sttime.out
  187. ud32 -C tpsysadm > curtime.out <<!
  188. SRVCNM .TMIB
  189. TA_OPERATION GET
  190. TA_CLASS T_SERVER
  191. TA_SERVERNAME BBL
  192. TA_FLAGS 65536
  193. TA_FILTER 33560683
  194. !
  195. RETVAL=${?}
  196. if [ ${RETVAL} -ne 0 ]
  197. then
  198. $ECHO_COUNTCLIENT "Could not get application current time\n"
  199. $ECHO_COUNTCLIENT "Please make sure both TUXDIR and TUXCONFIG are set properly.\n"
  200. return
  201. fi
  202. tmptime=`grep TA_CURTIME ./curtime.out | cut -d' ' -f2`
  203. ctime=`$ECHO_COUNTCLIENT "$(($tmptime/((3600*24))))"`
  204. rm -f ./curtime.out
  205. elapsedtime=`$ECHO_COUNTCLIENT "$(($ctime-$stime))"`
  206. $ECHO_COUNTCLIENT "\nThis Server's BBL started around $elapsedtime day(s) ago\n"
  207. }
  208. export tux_model
  209. ################################################################################
  210. #
  211. # gethighwatercnt() - check Tuxedo current client connections.
  212. #
  213. gethighwatercnt()
  214. {
  215. export FLDTBLDIR32="$TUXDIR/udataobj"
  216. export FIELDTBLS32="tpadm,Usysfl32"
  217. ud32 -C tpsysadm <<!
  218. SRVCNM .TMIB
  219. TA_OPERATION GET
  220. TA_CLASS T_MACHINE
  221. TA_FLAGS 65536
  222. TA_FILTER 33560667
  223. TA_FILTER 33560712
  224. !
  225. RETVAL=${?}
  226. if [ ${RETVAL} -ne 0 ]
  227. then
  228. $ECHO_COUNTCLIENT "Highwater mark couldn't be located, please provide to Oracle the latest ULOG file of the Tuxedo domain\n"
  229. fi
  230. }
  231. ################################################################################
  232. #
  233. # checkForTux() - Make sure Tuxedo is running and env variables are set up correctly.
  234. #
  235. checkForTux()
  236. {
  237. # Make sure a BBL is running on this machine and Tuxedo envionment variables set up correctly.
  238. BBLCNT=`ps -ef |grep BBL | grep -v DBBL | grep -v grep |wc -l`
  239. if [ ${BBLCNT} -gt 0 ]
  240. then
  241. if [ ${BBLCNT} -gt 1 ]
  242. then
  243. $ECHO_COUNTCLIENT "NOTE: ${BBLCNT} BBL processes are running on this machine\n" >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  244. $ECHO_COUNTCLIENT "There are ${BBLCNT} TUXEDO applications running on this machine\n" >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  245. $ECHO_COUNTCLIENT "NOTE: ${BBLCNT} BBL processes are running on this machine\n"
  246. $ECHO_COUNTCLIENT "There are ${BBLCNT} TUXEDO applications running on this machine\n"
  247. fi
  248. # Make sure necessary Environment Vars are set
  249. TUXDIR="${TUXDIR}"
  250. QUIT_COUNTCLIENTS=
  251. while [ -z "${TUXDIR}" -a -z "${QUIT_COUNTCLIENTS}" ]
  252. do
  253. $ECHO_COUNTCLIENT "TUXDIR not set.">&2
  254. $ECHO_COUNTCLIENT "Please enter the location where Tuxedo is installed,">&2
  255. $ECHO_COUNTCLIENT "or to quit the Tuxedo Countclients script and continue with the rest of the">&2
  256. $ECHO_COUNTCLIENT "Collection Tool, enter [quit or q]:" >&2
  257. read TUXDIR
  258. if [ "${TUXDIR}" = "q" -o "${TUXDIR}" = "quit" -o "${TUXDIR}" = "Q" ]; then
  259. QUIT_COUNTCLIENTS="yes"
  260. elif [ ! -d "${TUXDIR}/udataobj" ]; then
  261. $ECHO_COUNTCLIENT "Tuxedo udataobj directory does not exist in ${TUXDIR} ." >&2
  262. $ECHO_COUNTCLIENT "Please try again." >&2
  263. TUXDIR=
  264. fi
  265. done
  266. if [ "${QUIT_COUNTCLIENTS}" = "yes" ]; then
  267. $ECHO_COUNTCLIENT "User chose to quit countclients script." >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  268. else
  269. tuxcredentialValidation
  270. $ECHO_COUNTCLIENT "TUXDIR=${TUXDIR}" >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  271. . ${TUXDIR}/tux.env
  272. TUXCONFIG="$TUXCONFIG"
  273. while [ -z "${TUXCONFIG}" -a -z "${QUIT_COUNTCLIENTS}" ]
  274. do
  275. $ECHO_COUNTCLIENT "TUXCONFIG not set">&2
  276. $ECHO_COUNTCLIENT "Please enter the location of TUXCONFIG,">&2
  277. $ECHO_COUNTCLIENT "or to quit the Tuxedo Countclients script and continue with the rest of the">&2
  278. $ECHO_COUNTCLIENT "Collection Tool, enter [quit or q]:" >&2
  279. read TUXCONFIG
  280. if [ "${TUXCONFIG}" = "q" -o "${TUXCONFIG}" = "quit" -o "${TUXCONFIG}" = "Q" ]; then
  281. QUIT_COUNTCLIENTS="yes"
  282. elif [ ! -f "${TUXCONFIG}" ]; then
  283. $ECHO_COUNTCLIENT "TUXCONFIG does not exist." >&2
  284. $ECHO_COUNTCLIENT "Please try again." >&2
  285. TUXCONFIG=
  286. fi
  287. done
  288. if [ "${QUIT_COUNTCLIENTS}" = "yes" ]; then
  289. $ECHO_COUNTCLIENT "User chose to quit countclients script." >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  290. $ECHO_COUNTCLIENT "User chose to quit countclients script."
  291. else
  292. export TUXCONFIG="${TUXCONFIG}"
  293. $ECHO_COUNTCLIENT "TUXCONFIG=${TUXCONFIG}" >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  294. getconfigmodel >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  295. if [ "${tux_model}" = "SHM" ]
  296. then
  297. getSHMboottime >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  298. else
  299. getMPboottime >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  300. fi
  301. gethighwatercnt >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  302. RETVAL=${?}
  303. if [ ${RETVAL} -ne 0 ]
  304. then
  305. $ECHO_COUNTCLIENT "Could not connect to the running application to get the Tuxedo client count." >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  306. fi
  307. $TUXDIR/bin/tmunloadcf >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  308. RETVAL=${?}
  309. if [ ${RETVAL} -ne 0 ]
  310. then
  311. $ECHO_COUNTCLIENT "Could not get application configuration, please provide to Oracle the latest ULOG file of the Tuxedo domain" >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  312. $ECHO_COUNTCLIENT "Could not get application configuration, please provide to Oracle the latest ULOG file of the Tuxedo domain"
  313. fi
  314. exit 0
  315. fi
  316. fi
  317. else
  318. $ECHO_COUNTCLIENT "No Tuxedo BBL processes found on this machine." >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  319. $ECHO_COUNTCLIENT "Countclients configuration gathering script not run." >> $CT_TMP\${MACHINE_NAME}-countclients.txt
  320. $ECHO_COUNTCLIENT "No Tuxedo BBL processes found on this machine."
  321. $ECHO_COUNTCLIENT "Countclients configuration gathering script not run."
  322. exit 4
  323. fi
  324. }
  325. ################################################################################
  326. #
  327. #*********************************** MAIN **************************************
  328. #
  329. ################################################################################
  330. # command line defaults
  331. SCRIPT_OPTIONS=
  332. OUTPUT_DIR="."
  333. DEBUG="false"
  334. MACHINE_NAME=`uname -n`
  335. STANDALONE=
  336. # check to see if Collection is running, if not then print license.
  337. ps -eaf | grep Collection*.sh | grep -v grep >/dev/null 2>&1
  338. if [ $? -eq 0 ] ; then
  339. STANDALONE="false"
  340. else
  341. STANDALONE="true"
  342. fi
  343. if [ "${STANDALONE}" = "true" ] ; then
  344. # print welcome message
  345. beginMsg
  346. fi
  347. checkForTux