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
83 if [ $usevserver = yes ]
85 nodpkg="lost+found|ARCHIVES"
86 info "vserver root directory set to: $VROOTDIR"
87 for vserver in $found_vservers
89 info "examining vserver: $vserver"
90 running=`$VSERVERINFO $vserver RUNNING`
91 if [ "$running" = "1" ]; then
92 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
93 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
94 nodpkg="$nodpkg|$vserver"
97 nodpkg="$nodpkg|$vserver"
102 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
103 warning "can't find ${packagemgr}, skipping installed packages report."
109 if [ "$packages" == "yes" ]; then
110 if [ $usevserver = yes ]
112 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
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 [ "$packages" == "yes" ]; then
124 # don't expand * since it can be used in $packagemgroptions
126 debug "$packagemgr $packagemgroptions > $packagesfile"
127 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
132 ## System report ##############################
135 # here we grab a bunch of system stuff for a report
140 HASHES="#################################################################"
141 DASHES="-----------------------------------------------------------------"
143 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
147 echo $HASHES >> $sysreportfile
148 echo "# $STATUS" >> $sysreportfile
149 echo $HASHES >> $sysreportfile
151 echo "file: $1" >> $sysreportfile
152 echo $DASHES >> $sysreportfile
153 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
156 echo "directory: $1" >> $sysreportfile
157 echo $DASHES >> $sysreportfile
158 for file in `find $1 -maxdepth 3 -noleaf -type f`
163 echo $DASHES >> $sysreportfile
167 echo $HASHES >> $sysreportfile
168 echo "# $STATUS" >> $sysreportfile
169 echo $HASHES >> $sysreportfile
170 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
174 STATUS="Determining $os version:"
177 STATUS="Determinding your current hostname: "
178 catifexec "/bin/hostname"
180 STATUS="Getting the date:"
181 catifexec "/bin/date"
183 STATUS="Checking your systems current uptime and load average:"
184 catifexec "/usr/bin/uptime"
186 STATUS="Checking available memory:"
187 catifexec "/usr/bin/free"
189 STATUS="Checking free disk space:"
190 catifexec "/bin/df" "-al"
192 STATUS="Collecting what services run at what run level:"
193 if [ $os = "redhat" ]; then
194 catifexec "/sbin/chkconfig --list"
195 STATUS="Collecting information about /etc/rc.d:"
196 catiffile "/bin/ls /etc/rc.d/rc*.d/"
198 elif [ $os = "debian" ]; then
199 for level in 0 1 2 3 4 5 6 S; do
200 echo "Level: $level" >> $sysreportfile
201 for f in /etc/rc${level}.d/*; do
202 # Remove /etc/Knn or Snn from beginning
203 ff=$(echo $f | sed 's_/etc/rc..d/[KS][0-9][0-9]__')
204 if [ $f != $ff ]; then
205 echo $ff >> $sysreportfile
208 echo "" >> $sysreportfile
212 STATUS="Getting bootloader information:"
213 catifexec "/bin/ls -alR /boot"
215 # This covers sparc, alpha, and intel (respectively)
216 # updated for grub -mpg
217 if [ -f /etc/silo.conf ]; then
218 STATUS="Collecting information about the boot process (silo):"
219 catiffile "/etc/silo.conf"
221 if [ -f /etc/milo.conf ]; then
222 STATUS="Collecting information about the boot process (milo):"
223 catiffile "/etc/milo.conf"
225 if [ -f /etc/lilo.conf ]; then
226 STATUS="Collecting information about the boot process (lilo):"
227 catiffile "/etc/lilo.conf"
228 catifexec "/sbin/lilo -q"
230 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
231 STATUS="Collecting information about the boot process (grub.conf):"
232 catiffile "/boot/grub/grub.conf"
233 STATUS="Collecting information about the boot process (grub.map):"
234 catiffile "/boot/grub/device.map"
236 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
237 STATUS="Gathering information on cluster setup"
239 if [ -f /etc/cluster.conf ] ; then
240 catiffile "/etc/cluster.conf"
243 if [ -f /etc/cluster.xml ] ; then
244 catiffile "/etc/cluster.xml"
248 STATUS="Gathering sysctl information (sysctl -a):"
249 catiffile "sysctl -a 2>/dev/null"
250 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
251 catiffile "/etc/sysctl.conf"
253 STATUS="Gathering IP information (/sbin/ifconfig):"
254 catifexec "/sbin/ifconfig -a"
256 STATUS="Gathering additional IP information (/bin/ip addr list):"
257 catifexec "/bin/ip addr list"
259 STATUS="Checking network routes:"
260 catifexec "/sbin/route -n"
262 STATUS="Collecting Name Service Switch config information:"
263 catiffile "/etc/nsswitch.conf"
265 STATUS="Collecting information about system authentication (pam):"
266 catiffile "/etc/pam.conf"
267 catiffile "/etc/pam.d"
270 echo "Getting information about the kernel."
272 STATUS="Getting kernel version:"
273 catifexec "/bin/uname" "-a"
274 STATUS="Checking module information:"
275 catifexec "/sbin/lsmod"
276 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
278 STATUS="Checking module information $x:"
279 catifexec "/sbin/modinfo $x"
282 STATUS="Currently getting ksysms information:"
283 catifexec "/sbin/ksyms"
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/ksyms"
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 [ ! -x "$SFDISK" ]; then
435 warning "can't find sfdisk, skipping sfdisk report."
438 if [ ! -x "$HWINFO" ]; then
439 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."
452 ## PARTITIONS #############################
454 # here we use sfdisk to dump a listing of all the partitions.
455 # these files can be used to directly partition a disk of the same size.
457 if [ "$partitions" == "yes" ]; then
458 devices=`$SFDISK -l | grep "^Disk /dev" | cut -d/ -f2,3 | cut -d: -f1`
459 if [ "$devices" == "" ]; then
460 warning "No harddisks found"
462 for dev in $devices; do
463 [ -b $dev ] || continue
466 outputfile=${partitionsfile//__star__/$label}
467 debug "$SFDISK $sfdisk_options -d /$dev > $outputfile"
468 $SFDISK $sfdisk_options -d /$dev > $outputfile
472 ## HARDWARE #############################
475 # here we use hwinfo to dump a table listing all the
476 # information we can find on the hardware of this machine
479 if [ "$hardware" == "yes" ]; then
480 if [ -f $hardwarefile ]; then
484 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
485 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
486 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
487 for flag in cpu network disk bios pci; do
488 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
489 $HWINFO --$flag >> $hardwarefile