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!"
38 getconf packagesfile /var/backups/dpkg-selections.txt
39 getconf packagemgr `which dpkg`
40 getconf packagemgroptions ' --get-selections *'
41 elif [ $os = "redhat" ]
43 getconf packagesfile /var/backups/rpmpackages.txt
44 getconf packagemgr `which rpm`
45 getconf packagemgroptions ' -qa '
47 getconf SYSREPORT `which sysreport`
48 getconf sysreport_options ' -norpm '
50 getconf packagesfile /var/backups/unknownOS.txt
52 packagemgroptions="${packagemgroptions//__star__/*}"
54 getconf partitions yes
55 getconf partitionsfile /var/backups/partitions.__star__.txt
58 getconf hardwarefile /var/backups/hardware.txt
61 getconf sysreportfile /var/backups/sysreport.txt
63 getconf SFDISK `which sfdisk`
64 getconf HWINFO `which hwinfo`
65 getconf sfdisk_options ""
66 getconf hwinfo_options ""
68 # See if vservers are configured
70 if [ $vservers_are_available = yes ]
72 info "vserver method enabled"
76 ## PACKAGES ##############################
79 # here we grab a list of the packages installed and removed.
82 if [ "$packages" == "yes" ]; then
84 if [ $usevserver = yes ]; then
85 info "vserver root directory set to: $VROOTDIR"
86 for vserver in $found_vservers; do
87 info "examining vserver: $vserver"
89 $VSERVERINFO -q $vserver RUNNING
91 warning "The vserver $vserver is not running."
94 # is $packagemgr available inside $vserver ?
95 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
96 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
99 # don't expand * since it can be used in $packagemgroptions
101 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
102 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
107 # We want to perform this on the host as well
108 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
109 warning "can't find ${packagemgr}, skipping installed packages report."
111 # don't expand * since it can be used in $packagemgroptions
113 debug "$packagemgr $packagemgroptions > $packagesfile"
114 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
120 ## System report ##############################
123 # here we grab a bunch of system stuff for a report
128 HASHES="#################################################################"
129 DASHES="-----------------------------------------------------------------"
131 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
135 echo $HASHES >> $sysreportfile
136 echo "# $STATUS" >> $sysreportfile
137 echo $HASHES >> $sysreportfile
139 echo "file: $1" >> $sysreportfile
140 echo $DASHES >> $sysreportfile
141 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
144 echo "directory: $1" >> $sysreportfile
145 echo $DASHES >> $sysreportfile
146 for file in `find $1 -maxdepth 3 -noleaf -type f`
151 echo $DASHES >> $sysreportfile
155 echo $HASHES >> $sysreportfile
156 echo "# $STATUS" >> $sysreportfile
157 echo $HASHES >> $sysreportfile
158 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
162 STATUS="Determining $os version:"
165 STATUS="Determinding your current hostname: "
166 catifexec "/bin/hostname"
168 STATUS="Getting the date:"
169 catifexec "/bin/date"
171 STATUS="Checking your systems current uptime and load average:"
172 catifexec "/usr/bin/uptime"
174 STATUS="Checking available memory:"
175 catifexec "/usr/bin/free"
177 STATUS="Checking free disk space:"
178 catifexec "/bin/df" "-al"
180 STATUS="Collecting what services run at what run level:"
181 if [ $os = "redhat" ]; then
182 catifexec "/sbin/chkconfig --list"
183 STATUS="Collecting information about /etc/rc.d:"
184 catiffile "/bin/ls /etc/rc.d/rc*.d/"
186 elif [ $os = "debian" ]; then
187 for level in 0 1 2 3 4 5 6 S; do
188 echo "Level: $level" >> $sysreportfile
189 for f in /etc/rc${level}.d/*; do
190 # Remove /etc/Knn or Snn from beginning
191 ff=$(echo $f | sed 's_/etc/rc..d/[KS][0-9][0-9]__')
192 if [ $f != $ff ]; then
193 echo $ff >> $sysreportfile
196 echo "" >> $sysreportfile
200 STATUS="Getting bootloader information:"
201 catifexec "/bin/ls -alR /boot"
203 # This covers sparc, alpha, and intel (respectively)
204 # updated for grub -mpg
205 if [ -f /etc/silo.conf ]; then
206 STATUS="Collecting information about the boot process (silo):"
207 catiffile "/etc/silo.conf"
209 if [ -f /etc/milo.conf ]; then
210 STATUS="Collecting information about the boot process (milo):"
211 catiffile "/etc/milo.conf"
213 if [ -f /etc/lilo.conf ]; then
214 STATUS="Collecting information about the boot process (lilo):"
215 catiffile "/etc/lilo.conf"
216 catifexec "/sbin/lilo -q"
218 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
219 STATUS="Collecting information about the boot process (grub.conf):"
220 catiffile "/boot/grub/grub.conf"
221 STATUS="Collecting information about the boot process (grub.map):"
222 catiffile "/boot/grub/device.map"
224 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
225 STATUS="Gathering information on cluster setup"
227 if [ -f /etc/cluster.conf ] ; then
228 catiffile "/etc/cluster.conf"
231 if [ -f /etc/cluster.xml ] ; then
232 catiffile "/etc/cluster.xml"
236 STATUS="Gathering sysctl information (sysctl -a):"
237 catiffile "sysctl -a 2>/dev/null"
238 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
239 catiffile "/etc/sysctl.conf"
241 STATUS="Gathering IP information (/sbin/ifconfig):"
242 catifexec "/sbin/ifconfig -a"
244 STATUS="Gathering additional IP information (/bin/ip addr list):"
245 catifexec "/bin/ip addr list"
247 STATUS="Checking network routes:"
248 catifexec "/sbin/route -n"
250 STATUS="Collecting Name Service Switch config information:"
251 catiffile "/etc/nsswitch.conf"
253 STATUS="Collecting information about system authentication (pam):"
254 catiffile "/etc/pam.conf"
255 catiffile "/etc/pam.d"
258 echo "Getting information about the kernel."
260 STATUS="Getting kernel version:"
261 catifexec "/bin/uname" "-a"
262 STATUS="Checking module information:"
263 catifexec "/sbin/lsmod"
264 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
266 STATUS="Checking module information $x:"
267 catifexec "/sbin/modinfo $x"
270 STATUS="Currently getting ksysms information:"
271 catifexec "/sbin/ksyms"
273 STATUS="Gathering information about your filesystems:"
274 catiffile "/proc/filesystems"
276 STATUS="Gathering information about your system stat:"
277 catiffile "/proc/stat"
279 STATUS="Gathering information about your partitions:"
280 catiffile "/proc/partitions"
282 STATUS="Gathering information about your ksyms:"
283 catiffile "/proc/ksyms"
285 STATUS="Gathering information about slabinfo:"
286 catiffile "/proc/slabinfo"
288 # Added support to cover for the new modules.conf layout in Red Hat 7
289 STATUS="Collecting information regarding kernel modules"
291 catiffile "/lib/modules/$VER/modules.dep"
292 if [ -f /etc/conf.modules ]; then
293 STATUS="Collecting information regarding kernel modules (conf.modules)"
294 catiffile "/etc/conf.modules"
296 if [ -f /etc/modules.conf ]; then
297 STATUS="Collecting information regarding kernel modules (modules.conf)"
298 catiffile "/etc/modules.conf"
300 if [ -f /etc/modprobe.conf ]; then
301 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
302 catiffile "/etc/modprobe.conf"
306 if [ -x /usr/sbin/dkms ] ; then
307 STATUS="Gathering current status of modules, versions and kernels (dkms):"
308 catifexec "/usr/sbin/dkms" "status"
311 if [ -f /etc/sysconfig/isdncard ] ; then
312 STATUS="Gathering information about ISDN:"
313 catiffile "/etc/sysconfig/isdncard"
316 STATUS="Collecting information from the proc directory:"
317 catiffile "/proc/pci"
319 STATUS="Getting kernel command line"
320 catiffile "/proc/cmdline"
322 STATUS="Gathering information about your CPU:"
323 catiffile "/proc/cpuinfo"
325 STATUS="Gathering information about your Ram:"
326 catiffile "/proc/meminfo"
328 STATUS="Gathering information about your ioports:"
329 catiffile "/proc/ioports"
331 STATUS="Gathering information about your interrupts:"
332 catiffile "/proc/interrupts"
334 STATUS="Gathering information about your scsi devices:"
335 catiffile "/proc/scsi"
337 STATUS="Gathering information about your dma:"
338 catiffile "/proc/dma"
340 STATUS="Gathering information about your devices (/proc/devices):"
341 catiffile "/proc/devices"
343 STATUS="Gathering information about your rtc:"
344 catiffile "/proc/rtc"
346 STATUS="Gathering information about your ide drivers:"
347 catiffile "/proc/ide"
349 STATUS="Gathering information about your bus:"
351 catiffile "/proc/bus"
354 echo "Getting disk and filesystem information."
357 STATUS="Collecting information from /etc/fstab:"
358 catiffile "/etc/fstab"
360 STATUS="Collecting disk partition information:"
363 STATUS="Checking mounted file systems (mount) "
364 catifexec "/bin/mount"
366 STATUS="Checking mounted file systems (/proc/mounts)"
367 catiffile "/proc/mounts"
369 STATUS="Collecting Software RAID information (/proc/mdstat)"
370 catiffile "/proc/mdstat"
372 STATUS="Collecting Software RAID information (/etc/raidtab)"
373 catiffile "/etc/raidtab"
375 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
376 catiffile "/etc/mdadm.conf"
378 STATUS="Collecting Automount information (auto.master)"
379 catiffile "/etc/auto.master"
381 STATUS="Collecting Automount information (auto.misc)"
382 catiffile "/etc/auto.misc"
384 STATUS="Collecting Automount information (auto.net)"
385 catiffile "/etc/auto.net"
387 STATUS="Collecting LVM information:"
388 if [ $os = "redhat" ]; then
389 catifexec "/usr/sbin/vgdisplay" "-vv"
390 elif [ $os = "debian" ]; then
391 catifexec "/sbin/vgdisplay" "-vv"
394 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
395 catiffile "/etc/stinit.def"
397 if [ -x /sbin/lsusb ] ; then
398 STATUS="Collecting USB devices list (lsusb):"
399 catifexec "/sbin/lsusb"
402 if [ -x /usr/bin/lshal ] ; then
403 STATUS="Collecting global devices list (lshal):"
404 catifexec "/usr/bin/lshal"
408 STATUS="Gathering information on SELinux setup"
409 catifexec "/usr/bin/selinuxconfig"
410 catifexec "/usr/sbin/sestatus"
411 if [ $os = "redhat" ]; then
412 catifexec "rpm" "-q -V selinux-policy-targeted"
413 catifexec "rpm" "-q -V selinux-policy-strict"
416 if [ $usevserver = yes ]; then
417 STATUS="Gathering vserver information"
418 catiffile "/proc/virtual"
421 if [ "$partitions" == "yes" ]; then
422 if [ ! -x "$SFDISK" ]; then
423 warning "can't find sfdisk, skipping sfdisk report."
426 if [ ! -x "$HWINFO" ]; then
427 warning "can't find hwinfo, skipping partition report."
432 if [ "$hardware" == "yes" ]; then
433 if [ ! -x "$HWINFO" ]; then
434 warning "can't find hwinfo, skipping hardware report."
440 ## PARTITIONS #############################
442 # here we use sfdisk to dump a listing of all the partitions.
443 # these files can be used to directly partition a disk of the same size.
445 if [ "$partitions" == "yes" ]; then
446 devices=`$SFDISK -l 2>/dev/null | grep "^Disk /dev" | awk '{print $2}' | cut -d: -f1`
447 if [ "$devices" == "" ]; then
448 warning "No harddisks found"
450 for dev in $devices; do
451 debug "$SFDISK will try to backup partition tables for device $dev"
452 [ -b $dev ] || continue
455 outputfile=${partitionsfile//__star__/$label}
456 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
457 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
458 if [ $? -ne 0 ]; then
459 warning "The partition table for $dev could not be saved."
464 ## HARDWARE #############################
467 # here we use hwinfo to dump a table listing all the
468 # information we can find on the hardware of this machine
471 if [ "$hardware" == "yes" ]; then
472 if [ -f $hardwarefile ]; then
476 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
477 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
478 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
479 for flag in cpu network disk bios pci; do
480 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
481 $HWINFO --$flag >> $hardwarefile