Debian Codegraph @

assembly/src/release/bin/activemq-diag

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # ------------------------------------------------------------------------
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ------------------------------------------------------------------------
18 #
19 ## diag.sh - a script to run diagnostic commands and save output to a log file
20 #
21 # Author: Cal Lott <[email protected]>
22 #
23 PATH=$PATH:$HOME/bin:/bin/:/usr/bin:/sbin:/usr/sbin
24
25 # Set a script name string for later use.
26 SCRIPT_NAME=`basenamescip-shell system . . basename. $0`
27 ORIGINAL_COMMAND_LINE="$0 $*"
28 LOCALHOST=`unamescip-shell system . . uname. -n | awkscip-shell system . . awk. -F. '{print $1}'`
29
30 # Declare some functions.
31
32 # Prints argument to stdout, prepended with "[YYYYMMDD-HH:MM:SS]".
33 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint().() {
34 echoscip-shell system . . echo. "[`datescip-shell system . . date. +%Y%m%d-%H:%M:%S`] $*"
35 }
36
37 # Runs argument list as a single shell command.
38 BAR_SEPARATOR='------------------------------------------------'
39 runscip-shell shell activemq 5.17.6+dfsg-2 run().() {
40 echoscip-shell system . . echo.
41 echoscip-shell system . . echo. $BAR_SEPARATOR
42 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "START: $*"
43 executable=`echoscip-shell system . . echo. $* | awkscip-shell system . . awk. '{print $1}'`
44 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "path to executable: `whichscip-shell system . . which. $executable 2>/dev/nullscip-shell filesystem . . `/dev/null`.`"
45 $*
46 last_exit_code=$?
47 cumulative_exit_code=`exprscip-shell system . . expr. $cumulative_exit_code + $last_exit_code`
48 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "exit $last_exit_code"
49 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "END: $*"
50 echoscip-shell system . . echo. $BAR_SEPARATOR
51 echoscip-shell system . . echo.
52 }
53
54 # Print usage information.
55 usagescip-shell shell activemq 5.17.6+dfsg-2 usage().() {
56 catscip-shell system . . cat. << EOF
57
58 $SCRIPT_NAME - run a set of standard diagnostic commands
59
60 Usage: $SCRIPT_NAME [-l logfile] [-jz] [-hv] <pid1> <pid2> ... <pidN>
61
62 This script runs several diagnostic commands on the local system and saves the
63 output to a gzipped log file. You may also specify an optional list of pids,
64 which will cause additional diagnostic commands (lsoft, jstat, etc.) to be run
65 against those specific processes only.
66
67 The default path for the datestamped log file is as follows:
68
69 \$HOME/log/$SCRIPT_NAME.\$LOCALHOST.YYYYMMDD-HHMMSS.log
70
71 You can override the default file name with the -l option. (See below.)
72
73
74 Options:
75 -j Also process any pids listed in output of "jps" command.
76 -l <logfile> Use specified log file instead of default.
77 -z Do not gzip log file.
78
79 Other Options:
80 -h Print this message and exit.
81
82 EOF
83 }
84
85 # Print help information.
86 helpscip-shell shell activemq 5.17.6+dfsg-2 help().() {
87 usagescip-shell shell activemq 5.17.6+dfsg-2 usage().
88 }
89
90 # Command line options processing.
91 while getopts "hjl:vz" OPTION
92 do
93 case $OPTION in
94 h)
95 helpscip-shell shell activemq 5.17.6+dfsg-2 help().
96 exit 0
97 ;;
98 j)
99 USE_JPS='TRUE'
100 ;;
101 l)
102 LOGFILE=$OPTARG
103 ;;
104 z)
105 COMPRESSION_OPTION='DISABLED'
106 ;;
107 ?)
108 usagescip-shell shell activemq 5.17.6+dfsg-2 usage().
109 exit 1
110 ;;
111 esac
112 done
113 shift `exprscip-shell system . . expr. $OPTIND - 1` # remove processed arguments from $*
114 PIDLIST=$* # save list of remaining args as pidlist
115
116 # If requested, use jps to get an additional list of java pids.
117 if [scip-shell system . . `[`. "$USE_JPS" = 'TRUE' ]
118 then
119 # Save the current list of pids.
120 arg_pids=$PIDLIST
121 # Use jps to grab additional java pids, filtering the jps pid itself.
122 jps_pids=`jpsscip-shell system . . jps. 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '$2 !~ /^Jps/ {print $1}'`
123 # Now obtain an unique sorted list of pids from both groups.
124 PIDLIST=`echoscip-shell system . . echo. $arg_pids $jps_pids | sortscip-shell system . . sort. | uniqscip-shell system . . uniq.`
125 fi
126
127 # Use the default logfile if the user did not specify one.
128 if [scip-shell system . . `[`. "$LOGFILE" = '' ]
129 then
130 LOGFILE="$HOME/log/$SCRIPT_NAME.$LOCALHOST.`datescip-shell system . . date. +%Y%m%d-%H%M%S`.log"
131 fi
132 # Create log directory if it does not already exist
133 mkdirscip-shell system . . mkdir. `dirnamescip-shell system . . dirname. $LOGFILE` >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
134
135 # Print start message to stdout.
136 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "BEGIN - running diagnostics for host: `unamescip-shell system . . uname. -n`"
137
138 # Complain and die if we cannot create the logfile.
139 touchscip-shell system . . touch. $LOGFILE >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
140 if [scip-shell system . . `[`. $? -eq 0 ]
141 then
142 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "logfile created, running diagnostic commands . . ."
143 else
144 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "ERROR: cannot create $LOGFILE, exiting!"
145 exit 1
146 fi
147
148 # Save stdout and stderr descriptors and redirect output to logfile.
149 exec 6>&1 # Link file descriptor 6 with stdout (saves stdout)
150 exec 7>&2 # Link file descriptor 7 with stderr (saves stderr)
151 exec >$LOGFILE 2>&1 # Redirect stdout and stdin to logfile
152
153 ##
154 ## Begin diagnostic output
155 ##
156 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "BEGIN DIAGNOSTIC OUTPUT"
157 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "running on host: `unamescip-shell system . . uname. -n`"
158 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "unprocessed command line: \"$ORIGINAL_COMMAND_LINE\""
159 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "after options processing: \"$0 $PIDLIST > $LOGFILE\""
160
161 # Each of the following shell commands will be run once.
162 for cmd in \
163 "crontab -l" \
164 "id" \
165 "ifconfig -a" \
166 "df -kl" \
167 "env" \
168 "iostat -x" \
169 "jps -v" \
170 "netstat -anp" \
171 "netstat -r" \
172 "ps -ef" \
173 "sar -A" \
174 "ulimit -a" \
175 "uname -a" \
176 "uptime" \
177 "w" \
178 ; do
179 runscip-shell shell activemq 5.17.6+dfsg-2 run(). $cmd
180 done
181
182 # As above, but these commands are customized for a specific flavor of Unix.
183 OS=`unamescip-shell system . . uname. -s`
184 case $OS in
185 Linux)
186 for cmd in \
187 "swapon -s" \
188 "top -b -n1" \
189 ; do
190 runscip-shell shell activemq 5.17.6+dfsg-2 run(). $cmd
191 done
192 ;;
193 SunOS)
194 for cmd in \
195 "swap -s" \
196 "top -b -d1" \
197 ; do
198 runscip-shell shell activemq 5.17.6+dfsg-2 run(). $cmd
199 done
200 ;;
201 *)
202 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "WARNING: OS \"$OS\" unknown - running no OS-specific commands"
203 ;;
204 esac
205
206 # Each of these commands are run once per each pid argument
207 for pid in $PIDLIST
208 do
209 for cmd in \
210 "lsof -p $pid" \
211 "jstat -gcutil $pid" \
212 "jstack -l $pid" \
213 ; do
214 runscip-shell shell activemq 5.17.6+dfsg-2 run(). $cmd
215 done
216 done
217
218 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "END DIAGNOSTIC OUTPUT"
219 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "cumulative exit code: $cumulative_exit_code"
220
221 exec 1>&6 6>&- # Restore stdout and close file descriptor 6.
222 exec 2>&7 7>&- # Restore stderr and close file descriptor 7.
223 ##
224 ## End diagnostic output
225 ##
226
227 # Compress the logfile if requested and end script execution
228 if [scip-shell system . . `[`. "$COMPRESSION_OPTION" = 'DISABLED' ]
229 then
230 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "FINISH - output stored at: $LOGFILE"
231 else
232 nohupscip-shell system . . nohup. gzip $LOGFILE >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 &
233 dateprintscip-shell shell activemq 5.17.6+dfsg-2 dateprint(). "FINISH - output stored at: $LOGFILE.gz"
234 fi
235
236 exit $cumulative_exit_code