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 ""
76 # See if vservers are configured
78 if [ $vservers_are_available = yes ]
80 info "vserver method enabled"
84 ## PACKAGES ##############################
87 # here we grab a list of the packages installed and removed.
90 if [ "$packages" == "yes" ]; then
92 if [ $usevserver = yes ]; then
93 info "vserver root directory set to: $VROOTDIR"
94 for vserver in $found_vservers; do
95 info "examining vserver: $vserver"
97 $VSERVERINFO -q $vserver RUNNING
99 warning "The vserver $vserver is not running."
102 # is $packagemgr available inside $vserver ?
103 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
104 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
107 # don't expand * since it can be used in $packagemgroptions
109 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
110 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
115 # We want to perform this on the host as well
116 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
117 warning "can't find ${packagemgr}, skipping installed packages report."
119 # don't expand * since it can be used in $packagemgroptions
121 debug "$packagemgr $packagemgroptions > $packagesfile"
122 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
128 ## System report ##############################
131 # here we grab a bunch of system stuff for a report
136 HASHES="#################################################################"
137 DASHES="-----------------------------------------------------------------"
139 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
143 echo $HASHES >> $sysreportfile
144 echo "# $STATUS" >> $sysreportfile
145 echo $HASHES >> $sysreportfile
147 echo "file: $1" >> $sysreportfile
148 echo $DASHES >> $sysreportfile
149 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
152 echo "directory: $1" >> $sysreportfile
153 echo $DASHES >> $sysreportfile
154 for file in `find $1 -maxdepth 3 -noleaf -type f`
159 echo $DASHES >> $sysreportfile
163 echo $HASHES >> $sysreportfile
164 echo "# $STATUS" >> $sysreportfile
165 echo $HASHES >> $sysreportfile
166 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
170 STATUS="Determining $os version:"
173 STATUS="Determinding your current hostname: "
174 catifexec "/bin/hostname"
176 STATUS="Getting the date:"
177 catifexec "/bin/date"
179 STATUS="Checking your systems current uptime and load average:"
180 catifexec "/usr/bin/uptime"
182 STATUS="Checking available memory:"
183 catifexec "/usr/bin/free"
185 STATUS="Checking free disk space:"
186 catifexec "/bin/df" "-al"
188 STATUS="Collecting what services run at what run level:"
189 if [ $os = "redhat" ]; then
190 catifexec "/sbin/chkconfig --list"
191 STATUS="Collecting information about /etc/rc.d:"
192 catiffile "/bin/ls /etc/rc.d/rc*.d/"
194 elif [ $os = "debian" ]; then
195 for level in 0 1 2 3 4 5 6 S; do
196 echo "Level: $level" >> $sysreportfile
197 for f in /etc/rc${level}.d/*; do
198 # Remove /etc/Knn or Snn from beginning
199 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
200 if [ $f != $ff ]; then
201 echo $ff >> $sysreportfile
204 echo "" >> $sysreportfile
208 STATUS="Getting bootloader information:"
209 catifexec "/bin/ls -alR /boot"
211 # This covers sparc, alpha, and intel (respectively)
212 # updated for grub -mpg
213 if [ -f /etc/silo.conf ]; then
214 STATUS="Collecting information about the boot process (silo):"
215 catiffile "/etc/silo.conf"
217 if [ -f /etc/milo.conf ]; then
218 STATUS="Collecting information about the boot process (milo):"
219 catiffile "/etc/milo.conf"
221 if [ -f /etc/lilo.conf ]; then
222 STATUS="Collecting information about the boot process (lilo):"
223 catiffile "/etc/lilo.conf"
224 catifexec "/sbin/lilo -q"
226 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
227 STATUS="Collecting information about the boot process (grub.conf):"
228 catiffile "/boot/grub/grub.conf"
229 STATUS="Collecting information about the boot process (grub.map):"
230 catiffile "/boot/grub/device.map"
232 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
233 STATUS="Gathering information on cluster setup"
235 if [ -f /etc/cluster.conf ] ; then
236 catiffile "/etc/cluster.conf"
239 if [ -f /etc/cluster.xml ] ; then
240 catiffile "/etc/cluster.xml"
244 STATUS="Gathering sysctl information (sysctl -a):"
245 catiffile "sysctl -a 2>/dev/null"
246 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
247 catiffile "/etc/sysctl.conf"
249 STATUS="Gathering IP information (/sbin/ifconfig):"
250 catifexec "/sbin/ifconfig -a"
252 STATUS="Gathering additional IP information (/bin/ip addr list):"
253 catifexec "/bin/ip addr list"
255 STATUS="Checking network routes:"
256 catifexec "/sbin/route -n"
258 STATUS="Collecting Name Service Switch config information:"
259 catiffile "/etc/nsswitch.conf"
261 STATUS="Collecting information about system authentication (pam):"
262 catiffile "/etc/pam.conf"
263 catiffile "/etc/pam.d"
266 echo "Getting information about the kernel."
268 STATUS="Getting kernel version:"
269 catifexec "/bin/uname" "-a"
270 STATUS="Checking module information:"
271 catifexec "/sbin/lsmod"
272 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
274 STATUS="Checking module information $x:"
275 catifexec "/sbin/modinfo $x"
278 STATUS="Currently getting ksysms information:"
279 catifexec "/sbin/ksyms"
281 STATUS="Gathering information about your filesystems:"
282 catiffile "/proc/filesystems"
284 STATUS="Gathering information about your system stat:"
285 catiffile "/proc/stat"
287 STATUS="Gathering information about your partitions:"
288 catiffile "/proc/partitions"
290 STATUS="Gathering information about your ksyms:"
291 catiffile "/proc/ksyms"
293 STATUS="Gathering information about slabinfo:"
294 catiffile "/proc/slabinfo"
296 # Added support to cover for the new modules.conf layout in Red Hat 7
297 STATUS="Collecting information regarding kernel modules"
299 catiffile "/lib/modules/$VER/modules.dep"
300 if [ -f /etc/conf.modules ]; then
301 STATUS="Collecting information regarding kernel modules (conf.modules)"
302 catiffile "/etc/conf.modules"
304 if [ -f /etc/modules.conf ]; then
305 STATUS="Collecting information regarding kernel modules (modules.conf)"
306 catiffile "/etc/modules.conf"
308 if [ -f /etc/modprobe.conf ]; then
309 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
310 catiffile "/etc/modprobe.conf"
314 if [ -x /usr/sbin/dkms ] ; then
315 STATUS="Gathering current status of modules, versions and kernels (dkms):"
316 catifexec "/usr/sbin/dkms" "status"
319 if [ -f /etc/sysconfig/isdncard ] ; then
320 STATUS="Gathering information about ISDN:"
321 catiffile "/etc/sysconfig/isdncard"
324 STATUS="Collecting information from the proc directory:"
325 catiffile "/proc/pci"
327 STATUS="Getting kernel command line"
328 catiffile "/proc/cmdline"
330 STATUS="Gathering information about your CPU:"
331 catiffile "/proc/cpuinfo"
333 STATUS="Gathering information about your Ram:"
334 catiffile "/proc/meminfo"
336 STATUS="Gathering information about your ioports:"
337 catiffile "/proc/ioports"
339 STATUS="Gathering information about your interrupts:"
340 catiffile "/proc/interrupts"
342 STATUS="Gathering information about your scsi devices:"
343 catiffile "/proc/scsi"
345 STATUS="Gathering information about your dma:"
346 catiffile "/proc/dma"
348 STATUS="Gathering information about your devices (/proc/devices):"
349 catiffile "/proc/devices"
351 STATUS="Gathering information about your rtc:"
352 catiffile "/proc/rtc"
354 STATUS="Gathering information about your ide drivers:"
355 catiffile "/proc/ide"
357 STATUS="Gathering information about your bus:"
359 catiffile "/proc/bus"
362 echo "Getting disk and filesystem information."
365 STATUS="Collecting information from /etc/fstab:"
366 catiffile "/etc/fstab"
368 STATUS="Collecting disk partition information:"
371 STATUS="Checking mounted file systems (mount) "
372 catifexec "/bin/mount"
374 STATUS="Checking mounted file systems (/proc/mounts)"
375 catiffile "/proc/mounts"
377 STATUS="Collecting Software RAID information (/proc/mdstat)"
378 catiffile "/proc/mdstat"
380 STATUS="Collecting Software RAID information (/etc/raidtab)"
381 catiffile "/etc/raidtab"
383 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
384 catiffile "/etc/mdadm.conf"
386 STATUS="Collecting Automount information (auto.master)"
387 catiffile "/etc/auto.master"
389 STATUS="Collecting Automount information (auto.misc)"
390 catiffile "/etc/auto.misc"
392 STATUS="Collecting Automount information (auto.net)"
393 catiffile "/etc/auto.net"
395 STATUS="Collecting LVM information:"
396 if [ $os = "redhat" ]; then
397 catifexec "/usr/sbin/vgdisplay" "-vv"
398 elif [ $os = "debian" ]; then
399 catifexec "/sbin/vgdisplay" "-vv"
402 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
403 catiffile "/etc/stinit.def"
405 if [ -x /sbin/lsusb ] ; then
406 STATUS="Collecting USB devices list (lsusb):"
407 catifexec "/sbin/lsusb"
410 if [ -x /usr/bin/lshal ] ; then
411 STATUS="Collecting global devices list (lshal):"
412 catifexec "/usr/bin/lshal"
416 STATUS="Gathering information on SELinux setup"
417 catifexec "/usr/bin/selinuxconfig"
418 catifexec "/usr/sbin/sestatus"
419 if [ $os = "redhat" ]; then
420 catifexec "rpm" "-q -V selinux-policy-targeted"
421 catifexec "rpm" "-q -V selinux-policy-strict"
424 if [ $usevserver = yes ]; then
425 STATUS="Gathering vserver information"
426 catiffile "/proc/virtual"
429 if [ "$partitions" == "yes" ]; then
430 if [ "$dosfdisk" == "yes" ]; then
431 if [ ! -x "$SFDISK" ]; then
432 warning "can't find sfdisk, skipping sfdisk report."
436 if [ "$dohwinfo" == "yes" ]; then
437 if [ ! -x "$HWINFO" ]; then
438 warning "can't find hwinfo, skipping partition report."
444 if [ "$hardware" == "yes" ]; then
445 if [ ! -x "$HWINFO" ]; then
446 warning "can't find hwinfo, skipping hardware report."
451 ## HARDWARE #############################
454 # here we use hwinfo to dump a table listing all the
455 # information we can find on the hardware of this machine
458 if [ "$hardware" == "yes" ]; then
459 if [ "dohwinfo" == "yes" ]; then
460 if [ -f $hardwarefile ]; then
464 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
465 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
466 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
467 for flag in cpu network bios pci; do
468 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
469 $HWINFO --$flag >> $hardwarefile
475 ## PARTITIONS #############################
477 # here we use sfdisk to dump a listing of all the partitions.
478 # these files can be used to directly partition a disk of the same size.
480 if [ "$partitions" == "yes" ]; then
481 if [ "$dosfdisk" == "yes" ]; then
482 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
483 if [ "$devices" == "" ]; then
484 warning "No harddisks found"
486 for dev in $devices; do
487 debug "$SFDISK will try to backup partition tables for device $dev"
488 [ -b $dev ] || continue
491 outputfile=${partitionsfile//__star__/$label}
492 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
493 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
494 if [ $? -ne 0 ]; then
495 warning "The partition table for $dev could not be saved."
499 if [ "$dohwinfo" == "yes" ]; then
500 debug "Using $HWINFO to get all available disk information"
501 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
502 $HWINFO --disk >> $hardwarefile