1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # this handler will save various reports of vital system information.
4 # by default, all the reports are enabled and are saved in /var/backups.
6 # (1) a capture of the debconf package selection states. This file
7 # can be used to restore the answers to debconf questions for
8 # packages that you will be installing through (2) below. To
9 # do this, run: "debconf-set-selections < debconfsel.txt"
11 # (2) a list of all the packages installed and removed.
12 # this file can be used to restore the state of installed packages
13 # by running "dpkg --set-selections < dpkg-selections.txt and
14 # then run "apt-get -u dselect-upgrade". If you have the
15 # debconf-set-selections file from (1), you should restore those first.
17 # (3) the partition table of all disks.
18 # this partition table can be used to format another disk of
19 # the same size. this can be handy if using software raid and
20 # you have a disk go bad. just replace the disk and partition it
21 # by running "sfdisk /dev/sdb < partitions.sdb.txt"
22 # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
24 # (4) hardware information.
25 # write to a text file the important things which hwinfo can gleen.
28 if [ -f /etc/debian_version ]
31 debug "Debian detected"
32 osversion="/etc/debian_version"
33 elif [ -f /etc/redhat-release ]
36 debug "Redhat detected"
37 osversion="/etc/redhat-release"
39 warning "Unknown OS detected!"
42 getconf parentdir /var/backups
47 if [ ! -d $parentdir ]; then
53 getconf packagesfile $parentdir/dpkg-selections.txt
54 getconf packagemgr `which dpkg`
55 getconf packagemgroptions ' --get-selections *'
56 getconf selectionsfile $parentir/debconfsel.txt
57 getconf debconfgetselections `which debconf-get-selections`
58 elif [ $os = "redhat" ]
60 getconf packagesfile $parentdir/rpmpackages.txt
61 getconf packagemgr `which rpm`
62 getconf packagemgroptions ' -qa '
64 getconf SYSREPORT `which sysreport`
65 getconf sysreport_options ' -norpm '
67 getconf packagesfile $parentdir/unknownOS.txt
69 packagemgroptions="${packagemgroptions//__star__/*}"
71 getconf partitions yes
72 getconf partitionsfile $parentdir/partitions.__star__.txt
75 getconf hardwarefile $parentdir/hardware.txt
78 getconf sysreportfile $parentdir/sysreport.txt
80 getconf SFDISK `which sfdisk`
81 getconf HWINFO `which hwinfo`
82 getconf sfdisk_options ""
83 getconf hwinfo_options ""
87 # If vservers are configured, check that the ones listed in $vsnames are running.
89 if [ $vservers_are_available = yes ]; then
90 if [ "$vsnames" = all ]; then
91 vsnames="$found_vservers"
93 if ! vservers_running "$vsnames" ; then
94 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
96 info "Using vservers '$vsnames'"
100 ## PACKAGES ##############################
103 # here we grab a list of the packages installed and removed.
106 if [ "$packages" == "yes" ]; then
108 if [ $usevserver = yes ]; then
109 info "vserver root directory set to: $VROOTDIR"
110 for vserver in $vsnames; do
111 info "examining vserver: $vserver"
113 vservers_running $vserver
114 if [ $? -ne 0 ]; then
115 warning "The vserver $vserver is not running."
118 # is $packagemgr available inside $vserver ?
119 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
120 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
122 # don't expand * since it can be used in $packagemgroptions
124 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
125 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
128 # is $debconfgetselections available inside $vserver ?
129 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $debconfgetselections`" ]; then
130 warning "can't find $debconfgetselections in vserver $vserver, skipping package selection states."
132 debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
133 $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
138 # We want to perform this on the host as well
139 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
140 warning "can't find ${packagemgr}, skipping installed packages report."
142 # don't expand * since it can be used in $packagemgroptions
144 debug "$packagemgr $packagemgroptions > $packagesfile"
145 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
148 if [ -z "$debconfgetselections" ]; then
149 warning "can't find ${debconfgetselections}, skilling package selection states."
151 debug "$debconfgetselections > $selectionsfile"
152 $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
156 ## System report ##############################
159 # here we grab a bunch of system stuff for a report
164 HASHES="#################################################################"
165 DASHES="-----------------------------------------------------------------"
167 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
171 echo $HASHES >> $sysreportfile
172 echo "# $STATUS" >> $sysreportfile
173 echo $HASHES >> $sysreportfile
175 echo "file: $1" >> $sysreportfile
176 echo $DASHES >> $sysreportfile
177 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
180 echo "directory: $1" >> $sysreportfile
181 echo $DASHES >> $sysreportfile
182 for file in `find $1 -maxdepth 3 -noleaf -type f`
187 echo $DASHES >> $sysreportfile
192 echo $HASHES >> $sysreportfile
193 echo "# $STATUS" >> $sysreportfile
194 echo $HASHES >> $sysreportfile
195 $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
200 STATUS="Determining $os version:"
203 STATUS="Determinding your current hostname: "
204 catifexec "/bin/hostname"
206 STATUS="Getting the date:"
207 catifexec "/bin/date"
209 STATUS="Checking your systems current uptime and load average:"
210 catifexec "/usr/bin/uptime"
212 STATUS="Checking available memory:"
213 catifexec "/usr/bin/free"
215 STATUS="Checking free disk space:"
216 catifexec "/bin/df" "-al"
218 STATUS="Collecting what services run at what run level:"
219 if [ $os = "redhat" ]; then
220 catifexec "/sbin/chkconfig --list"
221 STATUS="Collecting information about /etc/rc.d:"
222 catiffile "/bin/ls /etc/rc.d/rc*.d/"
224 elif [ $os = "debian" ]; then
225 for level in 0 1 2 3 4 5 6 S; do
226 echo "Level: $level" >> $sysreportfile
227 for f in /etc/rc${level}.d/*; do
228 # Remove /etc/Knn or Snn from beginning
229 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
230 if [ $f != $ff ]; then
231 echo $ff >> $sysreportfile
234 echo "" >> $sysreportfile
238 STATUS="Getting bootloader information:"
239 catifexec "/bin/ls -alR /boot"
241 # This covers sparc, alpha, and intel (respectively)
242 # updated for grub -mpg
243 if [ -f /etc/silo.conf ]; then
244 STATUS="Collecting information about the boot process (silo):"
245 catiffile "/etc/silo.conf"
247 if [ -f /etc/milo.conf ]; then
248 STATUS="Collecting information about the boot process (milo):"
249 catiffile "/etc/milo.conf"
251 if [ -f /etc/lilo.conf ]; then
252 STATUS="Collecting information about the boot process (lilo):"
253 catiffile "/etc/lilo.conf"
254 catifexec "/sbin/lilo -q"
256 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
257 STATUS="Collecting information about the boot process (grub.conf):"
258 catiffile "/boot/grub/grub.conf"
259 STATUS="Collecting information about the boot process (grub.map):"
260 catiffile "/boot/grub/device.map"
262 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
263 STATUS="Gathering information on cluster setup"
265 if [ -f /etc/cluster.conf ] ; then
266 catiffile "/etc/cluster.conf"
269 if [ -f /etc/cluster.xml ] ; then
270 catiffile "/etc/cluster.xml"
274 STATUS="Gathering sysctl information (sysctl -a):"
275 catiffile "sysctl -a 2>/dev/null"
276 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
277 catiffile "/etc/sysctl.conf"
279 STATUS="Gathering IP information (/sbin/ifconfig):"
280 catifexec "/sbin/ifconfig -a"
282 STATUS="Gathering additional IP information (/bin/ip addr list):"
283 catifexec "/bin/ip addr list"
285 STATUS="Checking network routes:"
286 catifexec "/sbin/route -n"
288 STATUS="Collecting Name Service Switch config information:"
289 catiffile "/etc/nsswitch.conf"
291 STATUS="Collecting information about system authentication (pam):"
292 catiffile "/etc/pam.conf"
293 catiffile "/etc/pam.d"
296 echo "Getting information about the kernel."
298 STATUS="Getting kernel version:"
299 catifexec "/bin/uname" "-a"
300 STATUS="Checking module information:"
301 catifexec "/sbin/lsmod"
302 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
304 STATUS="Checking module information $x:"
305 catifexec "/sbin/modinfo $x"
308 STATUS="Gathering information about your filesystems:"
309 catiffile "/proc/filesystems"
311 STATUS="Gathering information about your system stat:"
312 catiffile "/proc/stat"
314 STATUS="Gathering information about your partitions:"
315 catiffile "/proc/partitions"
317 STATUS="Gathering information about your ksyms:"
318 catiffile "/proc/kallsyms"
320 STATUS="Gathering information about slabinfo:"
321 catiffile "/proc/slabinfo"
323 # Added support to cover for the new modules.conf layout in Red Hat 7
324 STATUS="Collecting information regarding kernel modules"
326 catiffile "/lib/modules/$VER/modules.dep"
327 if [ -f /etc/conf.modules ]; then
328 STATUS="Collecting information regarding kernel modules (conf.modules)"
329 catiffile "/etc/conf.modules"
331 if [ -f /etc/modules.conf ]; then
332 STATUS="Collecting information regarding kernel modules (modules.conf)"
333 catiffile "/etc/modules.conf"
335 if [ -f /etc/modprobe.conf ]; then
336 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
337 catiffile "/etc/modprobe.conf"
341 if [ -x /usr/sbin/dkms ] ; then
342 STATUS="Gathering current status of modules, versions and kernels (dkms):"
343 catifexec "/usr/sbin/dkms" "status"
346 if [ -f /etc/sysconfig/isdncard ] ; then
347 STATUS="Gathering information about ISDN:"
348 catiffile "/etc/sysconfig/isdncard"
351 STATUS="Collecting information from the proc directory:"
352 catiffile "/proc/pci"
354 STATUS="Getting kernel command line"
355 catiffile "/proc/cmdline"
357 STATUS="Gathering information about your CPU:"
358 catiffile "/proc/cpuinfo"
360 STATUS="Gathering information about your Ram:"
361 catiffile "/proc/meminfo"
363 STATUS="Gathering information about your ioports:"
364 catiffile "/proc/ioports"
366 STATUS="Gathering information about your interrupts:"
367 catiffile "/proc/interrupts"
369 STATUS="Gathering information about your scsi devices:"
370 catiffile "/proc/scsi"
372 STATUS="Gathering information about your dma:"
373 catiffile "/proc/dma"
375 STATUS="Gathering information about your devices (/proc/devices):"
376 catiffile "/proc/devices"
378 STATUS="Gathering information about your rtc:"
379 catiffile "/proc/rtc"
381 STATUS="Gathering information about your ide drivers:"
382 catiffile "/proc/ide"
384 STATUS="Gathering information about your bus:"
385 catifexec "/usr/bin/lspci"
386 catiffile "/proc/bus"
389 echo "Getting disk and filesystem information."
392 STATUS="Collecting information from /etc/fstab:"
393 catiffile "/etc/fstab"
395 STATUS="Collecting disk partition information:"
396 catifexec "/sbin/fdisk -l"
398 STATUS="Checking mounted file systems (mount) "
399 catifexec "/bin/mount"
401 STATUS="Checking mounted file systems (/proc/mounts)"
402 catiffile "/proc/mounts"
404 STATUS="Collecting Software RAID information (/proc/mdstat)"
405 catiffile "/proc/mdstat"
407 STATUS="Collecting Software RAID information (/etc/raidtab)"
408 catiffile "/etc/raidtab"
410 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
411 catiffile "/etc/mdadm.conf"
413 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
414 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
416 STATUS="Collecting Automount information (auto.master)"
417 catiffile "/etc/auto.master"
419 STATUS="Collecting Automount information (auto.misc)"
420 catiffile "/etc/auto.misc"
422 STATUS="Collecting Automount information (auto.net)"
423 catiffile "/etc/auto.net"
425 STATUS="Collecting LVM information:"
426 if [ $os = "redhat" ]; then
427 catifexec "/usr/sbin/vgdisplay" "-vv"
428 elif [ $os = "debian" ]; then
429 catifexec "/sbin/vgdisplay" "-vv"
432 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
433 catiffile "/etc/stinit.def"
435 if [ -x /sbin/lsusb ] ; then
436 STATUS="Collecting USB devices list (lsusb):"
437 catifexec "/sbin/lsusb"
440 if [ -x /usr/bin/lshal ] ; then
441 STATUS="Collecting global devices list (lshal):"
442 catifexec "/usr/bin/lshal"
446 STATUS="Gathering information on SELinux setup"
447 catifexec "/usr/bin/selinuxconfig"
448 catifexec "/usr/sbin/sestatus"
449 if [ $os = "redhat" ]; then
450 catifexec "rpm" "-q -V selinux-policy-targeted"
451 catifexec "rpm" "-q -V selinux-policy-strict"
454 if [ $usevserver = yes ]; then
455 STATUS="Gathering vserver information"
456 catiffile "/proc/virtual"
459 if [ "$partitions" == "yes" ]; then
460 if [ "$dosfdisk" == "yes" ]; then
461 if [ ! -x "$SFDISK" ]; then
462 warning "can't find sfdisk, skipping sfdisk report."
466 if [ "$dohwinfo" == "yes" ]; then
467 if [ ! -x "$HWINFO" ]; then
468 warning "can't find hwinfo, skipping partition report."
474 if [ "$hardware" == "yes" ]; then
475 if [ ! -x "$HWINFO" ]; then
476 warning "can't find hwinfo, skipping hardware report."
481 ## HARDWARE #############################
484 # here we use hwinfo to dump a table listing all the
485 # information we can find on the hardware of this machine
488 if [ "$hardware" == "yes" ]; then
489 if [ "dohwinfo" == "yes" ]; then
490 if [ -f $hardwarefile ]; then
494 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
495 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
496 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
497 for flag in cpu network bios pci; do
498 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
499 $HWINFO --$flag >> $hardwarefile
505 ## PARTITIONS #############################
507 # here we use sfdisk to dump a listing of all the partitions.
508 # these files can be used to directly partition a disk of the same size.
510 if [ "$partitions" == "yes" ]; then
511 if [ "$dosfdisk" == "yes" ]; then
512 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
513 if [ "$devices" == "" ]; then
514 warning "No harddisks found"
516 for dev in $devices; do
517 debug "$SFDISK will try to backup partition tables for device $dev"
518 [ -b $dev ] || continue
521 outputfile=${partitionsfile//__star__/$label}
522 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
523 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
524 if [ $? -ne 0 ]; then
525 warning "The partition table for $dev could not be saved."
529 if [ "$dohwinfo" == "yes" ]; then
530 debug "Using $HWINFO to get all available disk information"
531 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
532 $HWINFO --disk >> $hardwarefile