64
62
#internal state machine state for update
67
# Updates the VM with the current state
69
function UpdateState {
65
# UpdateState($state): Updates the VM with the given state.
70
68
if [ $update -eq 1 ]; then
71
69
vmware-xferlogs upd $1
75
function UpdateSpinner {
97
echo -en "\rPreparing Files: $SPINNER"
100
# Function: addtar copies whatever files and directories you give it to
101
# a self contained output directory for later tar'ing
102
# Working on copies could slow this down with VERY large files but:
103
# 1) We don't expect VERY large files
104
# 2) Since /proc files can be copied this preserves the tree without
105
# having to cat them all into a file.
106
# 3) tar barfs on open files like logs if it changes while it's tar'ing.
107
# Copying file first makes sure tar doesn't complain
113
DIR=$(dirname "$FILE")
114
if [ ! -d "${OUTPUT_DIR}$DIR" ]; then
115
mkdir -p "${OUTPUT_DIR}$DIR"
118
banner "Could not create ./${OUTPUT_DIR}$DIR... " \
119
"Have you run out of disk space?" "Continuing"
124
# Ignore stdout and handle errors.
126
cp -pr "$FILE" "${OUTPUT_DIR}$DIR" 2>/dev/null
128
# We could have failed to copy for several reasons
129
# If we path had a shell special character (* ? .)
130
# or if the file is in /proc
133
for line in "$DIR"/$FILENAME
135
if [ -e "$line" ]; then
136
# Ignore stdout and handle errors.
138
cp -pr "$line" "${OUTPUT_DIR}$DIR" 2>/dev/null
140
# If a file from /proc does not copy,
141
# ignore - they're funny.
142
# Otherwise, exit for failed copy.
144
echo "$line" | grep ^/proc > /dev/null
147
banner "Could not copy $line \
154
done # for each file in the list
160
# Function: runcmd executes the command ($1)
161
# redirected to a file ($2) and then adds that
162
# file to the list of files to tar.
163
# It then deletes the temp file since addtar makes a copy in its own
164
# selft contained area.
73
# addfile(): copies whatever files and directories you give it to
74
# a self contained output directory for later tar'ing
75
# Working on copies could slow this down with VERY large files but:
76
# 1) We don't expect VERY large files
77
# 2) Since /proc files can be copied this preserves the tree without
78
# having to cat them all into a file.
79
# 3) tar barfs on open files like logs if it changes while it's tar'ing.
80
# Copying file first makes sure tar doesn't complain
86
if [ ! -d "${OUTPUT_DIR}$dir" ]; then
87
mkdir -p "${OUTPUT_DIR}$dir"
90
banner "Could not create ./${OUTPUT_DIR}$dir... " \
91
"Have you run out of disk space?" "Continuing"
96
# Ignore stdout and handle errors.
97
cp -pRP "$file" "${OUTPUT_DIR}$dir" 2>/dev/null
99
banner "Could not copy '$file' to the tar area."
104
# addfiles(): adds a list of files to the archive.
113
# runcmd($cmd, $out): executes the command redirected to a file and then adds
114
# that file to the list of files to tar. It then deletes the temp file since
115
# addfile makes a copy in its own self-contained area.
167
118
$1 > $2 2>/dev/null
169
120
if [ $? != 0 ]; then
170
122
banner "Either could not run $1 or could not write to $2" \
171
"Do you have a full disk?" "Continuing..."
123
"Do you have a full disk? Continuing..."
177
banner "Could not delete $2. Continuing..."
131
# error(): prints an error message using the "banner" funtion and quits.
135
UpdateState $VMSUPPORT_ERROR
201
157
UpdateState $VMSUPPORT_BEGINNING
203
banner "VMware Linux Support Script $VER"
159
banner "VMware UNIX Support Script $VER"
205
161
# Check for root privledge
207
if [ $(id -u) != "0" ]; then
208
banner "You are not root, some system information can't be collected."
163
if [ `whoami` != 'root' ]; then
164
banner "You are not root, some system information can't be collected."
211
167
# Source /etc/profile. If we can't find it, it's the users problem to get
212
168
# their paths straight.
214
169
if [ -f /etc/profile ]; then
218
173
# Protect against non-default values of $IFS (Not all scripts in /etc/profile.d/
219
174
# are good citizens).
175
if [ `uname` != 'SunOS' ]; then
176
unset IFS 2>/dev/null
222
179
# make a subdir to put all your files in. die if it does not create
223
180
mkdir $OUTPUT_DIR
225
182
if [ $? != 0 ]; then
226
banner "Could not create ./${OUTPUT_DIR}... Exiting..." \
227
"Please cd to a directory to which you can write" # Thanks Adam!
232
# Add system configuration and log files. Wildcards
236
# Try to collect bootloader config.
237
if [ -e /etc/lilo.conf ]; then
238
addtar "/etc/lilo.conf"
241
# And for grub we are not sure about the exact default location so collect them
243
if [ -e /boot/grub/grub.conf ]; then
244
addtar "/boot/grub/grub.conf"
246
if [ -e /boot/grub/menu.lst ]; then
247
addtar "/boot/grub/menu.lst"
249
if [ -e /etc/grub.conf ]; then
250
addtar "/etc/grub.conf"
253
addtar "/etc/crontab"
254
addtar "/etc/cron.daily"
255
addtar "/etc/cron.hourly"
256
addtar "/etc/cron.monthly"
257
addtar "/etc/cron.weekly"
258
addtar "/etc/modules.conf"
259
addtar "/etc/ntp.conf"
260
addtar "/etc/security/*"
264
addtar "/etc/services"
266
addtar "/etc/vmware-tools/*"
267
addtar "/var/log/boot*"
268
addtar "/var/log/secure*"
269
addtar "/var/log/messages*"
270
addtar "/var/run/vmware-*"
272
# Add /proc with some exceptions. stdout redirected to /dev/null. Some files
273
# come and go and confuse find. Just send whatever works and don't scare user.
275
for procfile in `find /proc -type f 2>/dev/null| egrep -v kcore\|kmsg\|acpi\|pagemap\|/proc/$$`
280
# Commands to run ($1) and redirect to logs ($2) for
183
error "Could not create ./${OUTPUT_DIR}. Please cd to a directory to which "
187
banner "Collecting support information..."
189
# Common stuff that we gather for all OSes.
283
190
runcmd "echo vm-support version: $VER" "/tmp/vm-support-version.$$.txt"
284
runcmd "lspci -H1 -M" "/tmp/lspci1.$$.txt"
285
runcmd "lspci -H1 -M -vn" "/tmp/lspci2.$$.txt"
286
runcmd "/sbin/lsmod" "/tmp/modules.$$.txt"
287
runcmd "uname -a" "/tmp/uname.$$.txt"
192
addfiles /etc/vmware-tools
193
addfiles /var/log/boot*
194
addfiles /var/log/secure*
195
addfiles /var/log/messages*
196
addfiles /var/log/syslog*
197
addfiles /var/run/vmware-*
288
199
runcmd "df" "/tmp/df.$$.txt"
289
runcmd "cat /etc/issue" "/tmp/issue.$$.txt"
290
200
runcmd "ifconfig -a" "/tmp/ifconfig.$$.txt"
291
runcmd "rpm -qa" "/tmp/rpm-qa.$$.txt"
292
runcmd "netstat -lan" "/tmp/netstat-lan.$$.txt"
293
runcmd "route" "/tmp/route.$$.txt"
294
201
runcmd "mount" "/tmp/mount.$$.txt"
295
202
runcmd "dmesg" "/tmp/dmesg.$$.txt"
296
runcmd "free" "/tmp/free.$$.txt"
203
runcmd "ulimit -a" "/tmp/ulimit-a.$$.txt"
297
204
runcmd "uptime" "/tmp/uptime.$$.txt"
298
205
runcmd "date" "/tmp/date.$$.txt"
299
runcmd "ps auwwx" "/tmp/ps-auwwx.$$.txt"
300
runcmd "ulimit -a" "/tmp/ulimit-a.$$.txt"
301
206
runcmd "umask" "/tmp/umask.$$.txt"
209
# stageLinux(): gather information for troubleshooting Linux guests.
212
# Try to collect bootloader config.
213
if [ -e /etc/lilo.conf ]; then
214
addfiles /etc/lilo.conf
217
# And for grub we are not sure about the exact default location so collect them
219
if [ -e /boot/grub/grub.conf ]; then
220
addfile /boot/grub/grub.conf
222
if [ -e /boot/grub/menu.lst ]; then
223
addfile /boot/grub/menu.lst
225
if [ -e /etc/grub.conf ]; then
226
addfile /etc/grub.conf
229
addfile /etc/cron.daily
230
addfile /etc/cron.hourly
231
addfile /etc/cron.monthly
232
addfile /etc/cron.weekly
234
addfile /etc/modules.conf
235
addfile /etc/ntp.conf
236
addfile /etc/security
237
addfile /etc/services
239
# Commands to run ($1) and redirect to logs ($2) for inclusion.
240
runcmd "lspci -H1 -M" "/tmp/lspci1.$$.txt"
241
runcmd "lspci -H1 -M -vn" "/tmp/lspci2.$$.txt"
242
runcmd "/sbin/lsmod" "/tmp/modules.$$.txt"
243
runcmd "uname -a" "/tmp/uname.$$.txt"
244
runcmd "cat /etc/issue" "/tmp/issue.$$.txt"
245
runcmd "rpm -qa" "/tmp/rpm-qa.$$.txt"
246
runcmd "netstat -lan" "/tmp/netstat-lan.$$.txt"
247
runcmd "route" "/tmp/route.$$.txt"
248
runcmd "free" "/tmp/free.$$.txt"
252
# stageFreeBSD(): gather information for troubleshooting FreeBSD guests.
255
runcmd "ps auwwx" "/tmp/ps-auwwx.$$.txt"
258
# stageSolaris(): gather information for troubleshooting Solaris guests.
261
runcmd "ps eaf" "/tmp/ps-eaf.$$.txt"
267
# tar options: 'S' for sparse core files.
303
280
UpdateState $VMSUPPORT_RUNNING
306
# Perform the tar ('S' for sparse core files)
308
tar -czSvf $TARFILE $OUTPUT_DIR
282
banner "Creating tar archive..."
283
tar $TAR_OPTS $TARFILE $OUTPUT_DIR
310
285
if [ $? != 0 ]; then
311
banner "The tar did not successfully complete!" \
312
"If tar reports that a file changed while reading, please attempt to rerun this script."
286
banner "The tar process did not successfully complete!" \
287
"If tar reports that a file changed while reading, please attempt " \
288
"to rerun this script."
315
vmware-xferlogs enc $TARFILE &>/dev/null
292
TARFILE=${TARFILE}.gz
294
banner "Uploading archive to host..."
295
vmware-xferlogs enc $TARFILE 2>/dev/null
317
297
if [ $? != 0 ]; then
318
banner "could not transmit logs successfully, either the xmitLogs"\
319
"binary is not in the path, or you are not in a virtual machine"
298
banner "Could not transmit logs successfully: either the vmware-xferlogs " \
299
"binary is not in the path, or you are not in a virtual machine."
322
302
# Clean up temporary files