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 list of all the packages installed and removed.
7 # this file can be used to restore the state of installed packages
8 # by running "dpkg --set-selections < dpkg-selections.txt
10 # (2) the partition table of all disks.
11 # this partition table can be used to format another disk of
12 # the same size. this can be handy if using software raid and
13 # you have a disk go bad. just replace the disk and partition it
14 # by running "sfdisk /dev/sdb < partitions.sdb.txt"
15 # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
17 # (3) hardware information.
18 # write to a text file the important things which hwinfo can gleen.
21 if [ -f /etc/debian_version ]
24 debug "Debian detected"
25 osversion="/etc/debian_version"
26 elif [ -f /etc/redhat-release ]
29 debug "Redhat detected"
30 osversion="/etc/redhat-release"
32 warning "Unknown OS detected!"
35 getconf parentdir /var/backups
40 if [ ! -d $parentdir ]; then
46 getconf packagesfile $parentdir/dpkg-selections.txt
47 getconf packagemgr `which dpkg`
48 getconf packagemgroptions ' --get-selections *'
49 elif [ $os = "redhat" ]
51 getconf packagesfile $parentdir/rpmpackages.txt
52 getconf packagemgr `which rpm`
53 getconf packagemgroptions ' -qa '
55 getconf SYSREPORT `which sysreport`
56 getconf sysreport_options ' -norpm '
58 getconf packagesfile $parentdir/unknownOS.txt
60 packagemgroptions="${packagemgroptions//__star__/*}"
62 getconf partitions yes
63 getconf partitionsfile $parentdir/partitions.__star__.txt
66 getconf hardwarefile $parentdir/hardware.txt
69 getconf sysreportfile $parentdir/sysreport.txt
71 getconf SFDISK `which sfdisk`
72 getconf HWINFO `which hwinfo`
73 getconf sfdisk_options ""
74 getconf hwinfo_options ""
78 # If vservers are configured, check that the ones listed in $vsnames are running.
80 if [ $vservers_are_available = yes ]; then
81 if [ "$vsnames" = all ]; then
82 vsnames="$found_vservers"
84 if ! vservers_running "$vsnames" ; then
85 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
87 info "Using vservers '$vsnames'"
91 ## PACKAGES ##############################
94 # here we grab a list of the packages installed and removed.
97 if [ "$packages" == "yes" ]; then
99 if [ $usevserver = yes ]; then
100 info "vserver root directory set to: $VROOTDIR"
101 for vserver in $vsnames; do
102 info "examining vserver: $vserver"
104 vservers_running $vserver
105 if [ $? -ne 0 ]; then
106 warning "The vserver $vserver is not running."
109 # is $packagemgr available inside $vserver ?
110 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
111 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
114 # don't expand * since it can be used in $packagemgroptions
116 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
117 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
122 # We want to perform this on the host as well
123 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
124 warning "can't find ${packagemgr}, skipping installed packages report."
126 # don't expand * since it can be used in $packagemgroptions
128 debug "$packagemgr $packagemgroptions > $packagesfile"
129 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
135 ## System report ##############################
138 # here we grab a bunch of system stuff for a report
143 HASHES="#################################################################"
144 DASHES="-----------------------------------------------------------------"
146 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
150 echo $HASHES >> $sysreportfile
151 echo "# $STATUS" >> $sysreportfile
152 echo $HASHES >> $sysreportfile
154 echo "file: $1" >> $sysreportfile
155 echo $DASHES >> $sysreportfile
156 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
159 echo "directory: $1" >> $sysreportfile
160 echo $DASHES >> $sysreportfile
161 for file in `find $1 -maxdepth 3 -noleaf -type f`
166 echo $DASHES >> $sysreportfile
170 echo $HASHES >> $sysreportfile
171 echo "# $STATUS" >> $sysreportfile
172 echo $HASHES >> $sysreportfile
173 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
177 STATUS="Determining $os version:"
180 STATUS="Determinding your current hostname: "
181 catifexec "/bin/hostname"
183 STATUS="Getting the date:"
184 catifexec "/bin/date"
186 STATUS="Checking your systems current uptime and load average:"
187 catifexec "/usr/bin/uptime"
189 STATUS="Checking available memory:"
190 catifexec "/usr/bin/free"
192 STATUS="Checking free disk space:"
193 catifexec "/bin/df" "-al"
195 STATUS="Collecting what services run at what run level:"
196 if [ $os = "redhat" ]; then
197 catifexec "/sbin/chkconfig --list"
198 STATUS="Collecting information about /etc/rc.d:"
199 catiffile "/bin/ls /etc/rc.d/rc*.d/"
201 elif [ $os = "debian" ]; then
202 for level in 0 1 2 3 4 5 6 S; do
203 echo "Level: $level" >> $sysreportfile
204 for f in /etc/rc${level}.d/*; do
205 # Remove /etc/Knn or Snn from beginning
206 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
207 if [ $f != $ff ]; then
208 echo $ff >> $sysreportfile
211 echo "" >> $sysreportfile
215 STATUS="Getting bootloader information:"
216 catifexec "/bin/ls -alR /boot"
218 # This covers sparc, alpha, and intel (respectively)
219 # updated for grub -mpg
220 if [ -f /etc/silo.conf ]; then
221 STATUS="Collecting information about the boot process (silo):"
222 catiffile "/etc/silo.conf"
224 if [ -f /etc/milo.conf ]; then
225 STATUS="Collecting information about the boot process (milo):"
226 catiffile "/etc/milo.conf"
228 if [ -f /etc/lilo.conf ]; then
229 STATUS="Collecting information about the boot process (lilo):"
230 catiffile "/etc/lilo.conf"
231 catifexec "/sbin/lilo -q"
233 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
234 STATUS="Collecting information about the boot process (grub.conf):"
235 catiffile "/boot/grub/grub.conf"
236 STATUS="Collecting information about the boot process (grub.map):"
237 catiffile "/boot/grub/device.map"
239 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
240 STATUS="Gathering information on cluster setup"
242 if [ -f /etc/cluster.conf ] ; then
243 catiffile "/etc/cluster.conf"
246 if [ -f /etc/cluster.xml ] ; then
247 catiffile "/etc/cluster.xml"
251 STATUS="Gathering sysctl information (sysctl -a):"
252 catiffile "sysctl -a 2>/dev/null"
253 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
254 catiffile "/etc/sysctl.conf"
256 STATUS="Gathering IP information (/sbin/ifconfig):"
257 catifexec "/sbin/ifconfig -a"
259 STATUS="Gathering additional IP information (/bin/ip addr list):"
260 catifexec "/bin/ip addr list"
262 STATUS="Checking network routes:"
263 catifexec "/sbin/route -n"
265 STATUS="Collecting Name Service Switch config information:"
266 catiffile "/etc/nsswitch.conf"
268 STATUS="Collecting information about system authentication (pam):"
269 catiffile "/etc/pam.conf"
270 catiffile "/etc/pam.d"
273 echo "Getting information about the kernel."
275 STATUS="Getting kernel version:"
276 catifexec "/bin/uname" "-a"
277 STATUS="Checking module information:"
278 catifexec "/sbin/lsmod"
279 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
281 STATUS="Checking module information $x:"
282 catifexec "/sbin/modinfo $x"
285 STATUS="Gathering information about your filesystems:"
286 catiffile "/proc/filesystems"
288 STATUS="Gathering information about your system stat:"
289 catiffile "/proc/stat"
291 STATUS="Gathering information about your partitions:"
292 catiffile "/proc/partitions"
294 STATUS="Gathering information about your ksyms:"
295 catiffile "/proc/kallsyms"
297 STATUS="Gathering information about slabinfo:"
298 catiffile "/proc/slabinfo"
300 # Added support to cover for the new modules.conf layout in Red Hat 7
301 STATUS="Collecting information regarding kernel modules"
303 catiffile "/lib/modules/$VER/modules.dep"
304 if [ -f /etc/conf.modules ]; then
305 STATUS="Collecting information regarding kernel modules (conf.modules)"
306 catiffile "/etc/conf.modules"
308 if [ -f /etc/modules.conf ]; then
309 STATUS="Collecting information regarding kernel modules (modules.conf)"
310 catiffile "/etc/modules.conf"
312 if [ -f /etc/modprobe.conf ]; then
313 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
314 catiffile "/etc/modprobe.conf"
318 if [ -x /usr/sbin/dkms ] ; then
319 STATUS="Gathering current status of modules, versions and kernels (dkms):"
320 catifexec "/usr/sbin/dkms" "status"
323 if [ -f /etc/sysconfig/isdncard ] ; then
324 STATUS="Gathering information about ISDN:"
325 catiffile "/etc/sysconfig/isdncard"
328 STATUS="Collecting information from the proc directory:"
329 catiffile "/proc/pci"
331 STATUS="Getting kernel command line"
332 catiffile "/proc/cmdline"
334 STATUS="Gathering information about your CPU:"
335 catiffile "/proc/cpuinfo"
337 STATUS="Gathering information about your Ram:"
338 catiffile "/proc/meminfo"
340 STATUS="Gathering information about your ioports:"
341 catiffile "/proc/ioports"
343 STATUS="Gathering information about your interrupts:"
344 catiffile "/proc/interrupts"
346 STATUS="Gathering information about your scsi devices:"
347 catiffile "/proc/scsi"
349 STATUS="Gathering information about your dma:"
350 catiffile "/proc/dma"
352 STATUS="Gathering information about your devices (/proc/devices):"
353 catiffile "/proc/devices"
355 STATUS="Gathering information about your rtc:"
356 catiffile "/proc/rtc"
358 STATUS="Gathering information about your ide drivers:"
359 catiffile "/proc/ide"
361 STATUS="Gathering information about your bus:"
363 catiffile "/proc/bus"
366 echo "Getting disk and filesystem information."
369 STATUS="Collecting information from /etc/fstab:"
370 catiffile "/etc/fstab"
372 STATUS="Collecting disk partition information:"
375 STATUS="Checking mounted file systems (mount) "
376 catifexec "/bin/mount"
378 STATUS="Checking mounted file systems (/proc/mounts)"
379 catiffile "/proc/mounts"
381 STATUS="Collecting Software RAID information (/proc/mdstat)"
382 catiffile "/proc/mdstat"
384 STATUS="Collecting Software RAID information (/etc/raidtab)"
385 catiffile "/etc/raidtab"
387 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
388 catiffile "/etc/mdadm.conf"
390 STATUS="Collecting Automount information (auto.master)"
391 catiffile "/etc/auto.master"
393 STATUS="Collecting Automount information (auto.misc)"
394 catiffile "/etc/auto.misc"
396 STATUS="Collecting Automount information (auto.net)"
397 catiffile "/etc/auto.net"
399 STATUS="Collecting LVM information:"
400 if [ $os = "redhat" ]; then
401 catifexec "/usr/sbin/vgdisplay" "-vv"
402 elif [ $os = "debian" ]; then
403 catifexec "/sbin/vgdisplay" "-vv"
406 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
407 catiffile "/etc/stinit.def"
409 if [ -x /sbin/lsusb ] ; then
410 STATUS="Collecting USB devices list (lsusb):"
411 catifexec "/sbin/lsusb"
414 if [ -x /usr/bin/lshal ] ; then
415 STATUS="Collecting global devices list (lshal):"
416 catifexec "/usr/bin/lshal"
420 STATUS="Gathering information on SELinux setup"
421 catifexec "/usr/bin/selinuxconfig"
422 catifexec "/usr/sbin/sestatus"
423 if [ $os = "redhat" ]; then
424 catifexec "rpm" "-q -V selinux-policy-targeted"
425 catifexec "rpm" "-q -V selinux-policy-strict"
428 if [ $usevserver = yes ]; then
429 STATUS="Gathering vserver information"
430 catiffile "/proc/virtual"
433 if [ "$partitions" == "yes" ]; then
434 if [ "$dosfdisk" == "yes" ]; then
435 if [ ! -x "$SFDISK" ]; then
436 warning "can't find sfdisk, skipping sfdisk report."
440 if [ "$dohwinfo" == "yes" ]; then
441 if [ ! -x "$HWINFO" ]; then
442 warning "can't find hwinfo, skipping partition report."
448 if [ "$hardware" == "yes" ]; then
449 if [ ! -x "$HWINFO" ]; then
450 warning "can't find hwinfo, skipping hardware report."
455 ## HARDWARE #############################
458 # here we use hwinfo to dump a table listing all the
459 # information we can find on the hardware of this machine
462 if [ "$hardware" == "yes" ]; then
463 if [ "dohwinfo" == "yes" ]; then
464 if [ -f $hardwarefile ]; then
468 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
469 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
470 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
471 for flag in cpu network bios pci; do
472 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
473 $HWINFO --$flag >> $hardwarefile
479 ## PARTITIONS #############################
481 # here we use sfdisk to dump a listing of all the partitions.
482 # these files can be used to directly partition a disk of the same size.
484 if [ "$partitions" == "yes" ]; then
485 if [ "$dosfdisk" == "yes" ]; then
486 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
487 if [ "$devices" == "" ]; then
488 warning "No harddisks found"
490 for dev in $devices; do
491 debug "$SFDISK will try to backup partition tables for device $dev"
492 [ -b $dev ] || continue
495 outputfile=${partitionsfile//__star__/$label}
496 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
497 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
498 if [ $? -ne 0 ]; then
499 warning "The partition table for $dev could not be saved."
503 if [ "$dohwinfo" == "yes" ]; then
504 debug "Using $HWINFO to get all available disk information"
505 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
506 $HWINFO --disk >> $hardwarefile