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!"
40 getconf packagesfile /var/backups/dpkg-selections.txt
41 getconf packagemgr `which dpkg`
42 getconf packagemgroptions ' --get-selections *'
43 elif [ $os = "redhat" ]
45 getconf packagesfile /var/backups/rpmpackages.txt
46 getconf packagemgr `which rpm`
47 getconf packagemgroptions ' -qa '
49 getconf SYSREPORT `which sysreport`
50 getconf sysreport_options ' -norpm '
52 getconf packagesfile /var/backups/unknownOS.txt
54 packagemgroptions="${packagemgroptions//__star__/*}"
56 getconf partitions yes
57 getconf partitionsfile /var/backups/partitions.__star__.txt
60 getconf hardwarefile /var/backups/hardware.txt
63 getconf sysreportfile /var/backups/sysreport.txt
65 getconf SFDISK `which sfdisk`
66 getconf HWINFO `which hwinfo`
67 getconf sfdisk_options ""
68 getconf hwinfo_options ""
70 # See if vservers are configured
72 if [ $vservers_are_available = yes ]
74 info "vserver method enabled"
78 ## PACKAGES ##############################
81 # here we grab a list of the packages installed and removed.
84 if [ "$packages" == "yes" ]; then
86 if [ $usevserver = yes ]; then
87 info "vserver root directory set to: $VROOTDIR"
88 for vserver in $found_vservers; do
89 info "examining vserver: $vserver"
91 $VSERVERINFO -q $vserver RUNNING
93 warning "The vserver $vserver is not running."
96 # is $packagemgr available inside $vserver ?
97 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
98 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
101 # don't expand * since it can be used in $packagemgroptions
103 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
104 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
109 # We want to perform this on the host as well
110 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
111 warning "can't find ${packagemgr}, skipping installed packages report."
113 # don't expand * since it can be used in $packagemgroptions
115 debug "$packagemgr $packagemgroptions > $packagesfile"
116 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
122 ## System report ##############################
125 # here we grab a bunch of system stuff for a report
130 HASHES="#################################################################"
131 DASHES="-----------------------------------------------------------------"
133 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
137 echo $HASHES >> $sysreportfile
138 echo "# $STATUS" >> $sysreportfile
139 echo $HASHES >> $sysreportfile
141 echo "file: $1" >> $sysreportfile
142 echo $DASHES >> $sysreportfile
143 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
146 echo "directory: $1" >> $sysreportfile
147 echo $DASHES >> $sysreportfile
148 for file in `find $1 -maxdepth 3 -noleaf -type f`
153 echo $DASHES >> $sysreportfile
157 echo $HASHES >> $sysreportfile
158 echo "# $STATUS" >> $sysreportfile
159 echo $HASHES >> $sysreportfile
160 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
164 STATUS="Determining $os version:"
167 STATUS="Determinding your current hostname: "
168 catifexec "/bin/hostname"
170 STATUS="Getting the date:"
171 catifexec "/bin/date"
173 STATUS="Checking your systems current uptime and load average:"
174 catifexec "/usr/bin/uptime"
176 STATUS="Checking available memory:"
177 catifexec "/usr/bin/free"
179 STATUS="Checking free disk space:"
180 catifexec "/bin/df" "-al"
182 STATUS="Collecting what services run at what run level:"
183 if [ $os = "redhat" ]; then
184 catifexec "/sbin/chkconfig --list"
185 STATUS="Collecting information about /etc/rc.d:"
186 catiffile "/bin/ls /etc/rc.d/rc*.d/"
188 elif [ $os = "debian" ]; then
189 for level in 0 1 2 3 4 5 6 S; do
190 echo "Level: $level" >> $sysreportfile
191 for f in /etc/rc${level}.d/*; do
192 # Remove /etc/Knn or Snn from beginning
193 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
194 if [ $f != $ff ]; then
195 echo $ff >> $sysreportfile
198 echo "" >> $sysreportfile
202 STATUS="Getting bootloader information:"
203 catifexec "/bin/ls -alR /boot"
205 # This covers sparc, alpha, and intel (respectively)
206 # updated for grub -mpg
207 if [ -f /etc/silo.conf ]; then
208 STATUS="Collecting information about the boot process (silo):"
209 catiffile "/etc/silo.conf"
211 if [ -f /etc/milo.conf ]; then
212 STATUS="Collecting information about the boot process (milo):"
213 catiffile "/etc/milo.conf"
215 if [ -f /etc/lilo.conf ]; then
216 STATUS="Collecting information about the boot process (lilo):"
217 catiffile "/etc/lilo.conf"
218 catifexec "/sbin/lilo -q"
220 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
221 STATUS="Collecting information about the boot process (grub.conf):"
222 catiffile "/boot/grub/grub.conf"
223 STATUS="Collecting information about the boot process (grub.map):"
224 catiffile "/boot/grub/device.map"
226 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
227 STATUS="Gathering information on cluster setup"
229 if [ -f /etc/cluster.conf ] ; then
230 catiffile "/etc/cluster.conf"
233 if [ -f /etc/cluster.xml ] ; then
234 catiffile "/etc/cluster.xml"
238 STATUS="Gathering sysctl information (sysctl -a):"
239 catiffile "sysctl -a 2>/dev/null"
240 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
241 catiffile "/etc/sysctl.conf"
243 STATUS="Gathering IP information (/sbin/ifconfig):"
244 catifexec "/sbin/ifconfig -a"
246 STATUS="Gathering additional IP information (/bin/ip addr list):"
247 catifexec "/bin/ip addr list"
249 STATUS="Checking network routes:"
250 catifexec "/sbin/route -n"
252 STATUS="Collecting Name Service Switch config information:"
253 catiffile "/etc/nsswitch.conf"
255 STATUS="Collecting information about system authentication (pam):"
256 catiffile "/etc/pam.conf"
257 catiffile "/etc/pam.d"
260 echo "Getting information about the kernel."
262 STATUS="Getting kernel version:"
263 catifexec "/bin/uname" "-a"
264 STATUS="Checking module information:"
265 catifexec "/sbin/lsmod"
266 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
268 STATUS="Checking module information $x:"
269 catifexec "/sbin/modinfo $x"
272 STATUS="Currently getting ksysms information:"
273 catifexec "/sbin/ksyms"
275 STATUS="Gathering information about your filesystems:"
276 catiffile "/proc/filesystems"
278 STATUS="Gathering information about your system stat:"
279 catiffile "/proc/stat"
281 STATUS="Gathering information about your partitions:"
282 catiffile "/proc/partitions"
284 STATUS="Gathering information about your ksyms:"
285 catiffile "/proc/ksyms"
287 STATUS="Gathering information about slabinfo:"
288 catiffile "/proc/slabinfo"
290 # Added support to cover for the new modules.conf layout in Red Hat 7
291 STATUS="Collecting information regarding kernel modules"
293 catiffile "/lib/modules/$VER/modules.dep"
294 if [ -f /etc/conf.modules ]; then
295 STATUS="Collecting information regarding kernel modules (conf.modules)"
296 catiffile "/etc/conf.modules"
298 if [ -f /etc/modules.conf ]; then
299 STATUS="Collecting information regarding kernel modules (modules.conf)"
300 catiffile "/etc/modules.conf"
302 if [ -f /etc/modprobe.conf ]; then
303 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
304 catiffile "/etc/modprobe.conf"
308 if [ -x /usr/sbin/dkms ] ; then
309 STATUS="Gathering current status of modules, versions and kernels (dkms):"
310 catifexec "/usr/sbin/dkms" "status"
313 if [ -f /etc/sysconfig/isdncard ] ; then
314 STATUS="Gathering information about ISDN:"
315 catiffile "/etc/sysconfig/isdncard"
318 STATUS="Collecting information from the proc directory:"
319 catiffile "/proc/pci"
321 STATUS="Getting kernel command line"
322 catiffile "/proc/cmdline"
324 STATUS="Gathering information about your CPU:"
325 catiffile "/proc/cpuinfo"
327 STATUS="Gathering information about your Ram:"
328 catiffile "/proc/meminfo"
330 STATUS="Gathering information about your ioports:"
331 catiffile "/proc/ioports"
333 STATUS="Gathering information about your interrupts:"
334 catiffile "/proc/interrupts"
336 STATUS="Gathering information about your scsi devices:"
337 catiffile "/proc/scsi"
339 STATUS="Gathering information about your dma:"
340 catiffile "/proc/dma"
342 STATUS="Gathering information about your devices (/proc/devices):"
343 catiffile "/proc/devices"
345 STATUS="Gathering information about your rtc:"
346 catiffile "/proc/rtc"
348 STATUS="Gathering information about your ide drivers:"
349 catiffile "/proc/ide"
351 STATUS="Gathering information about your bus:"
353 catiffile "/proc/bus"
356 echo "Getting disk and filesystem information."
359 STATUS="Collecting information from /etc/fstab:"
360 catiffile "/etc/fstab"
362 STATUS="Collecting disk partition information:"
365 STATUS="Checking mounted file systems (mount) "
366 catifexec "/bin/mount"
368 STATUS="Checking mounted file systems (/proc/mounts)"
369 catiffile "/proc/mounts"
371 STATUS="Collecting Software RAID information (/proc/mdstat)"
372 catiffile "/proc/mdstat"
374 STATUS="Collecting Software RAID information (/etc/raidtab)"
375 catiffile "/etc/raidtab"
377 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
378 catiffile "/etc/mdadm.conf"
380 STATUS="Collecting Automount information (auto.master)"
381 catiffile "/etc/auto.master"
383 STATUS="Collecting Automount information (auto.misc)"
384 catiffile "/etc/auto.misc"
386 STATUS="Collecting Automount information (auto.net)"
387 catiffile "/etc/auto.net"
389 STATUS="Collecting LVM information:"
390 if [ $os = "redhat" ]; then
391 catifexec "/usr/sbin/vgdisplay" "-vv"
392 elif [ $os = "debian" ]; then
393 catifexec "/sbin/vgdisplay" "-vv"
396 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
397 catiffile "/etc/stinit.def"
399 if [ -x /sbin/lsusb ] ; then
400 STATUS="Collecting USB devices list (lsusb):"
401 catifexec "/sbin/lsusb"
404 if [ -x /usr/bin/lshal ] ; then
405 STATUS="Collecting global devices list (lshal):"
406 catifexec "/usr/bin/lshal"
410 STATUS="Gathering information on SELinux setup"
411 catifexec "/usr/bin/selinuxconfig"
412 catifexec "/usr/sbin/sestatus"
413 if [ $os = "redhat" ]; then
414 catifexec "rpm" "-q -V selinux-policy-targeted"
415 catifexec "rpm" "-q -V selinux-policy-strict"
418 if [ $usevserver = yes ]; then
419 STATUS="Gathering vserver information"
420 catiffile "/proc/virtual"
423 if [ "$partitions" == "yes" ]; then
424 if [ "$dosfdisk" == "yes" ]; then
425 if [ ! -x "$SFDISK" ]; then
426 warning "can't find sfdisk, skipping sfdisk report."
430 if [ "$dohwinfo" == "yes" ]; then
431 if [ ! -x "$HWINFO" ]; then
432 warning "can't find hwinfo, skipping partition report."
438 if [ "$hardware" == "yes" ]; then
439 if [ ! -x "$HWINFO" ]; then
440 warning "can't find hwinfo, skipping hardware report."
445 ## HARDWARE #############################
448 # here we use hwinfo to dump a table listing all the
449 # information we can find on the hardware of this machine
452 if [ "$hardware" == "yes" ]; then
453 if [ "dohwinfo" == "yes" ]; then
454 if [ -f $hardwarefile ]; then
458 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
459 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
460 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
461 for flag in cpu network bios pci; do
462 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
463 $HWINFO --$flag >> $hardwarefile
469 ## PARTITIONS #############################
471 # here we use sfdisk to dump a listing of all the partitions.
472 # these files can be used to directly partition a disk of the same size.
474 if [ "$partitions" == "yes" ]; then
475 if [ "$dosfdisk" == "yes" ]; then
476 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
477 if [ "$devices" == "" ]; then
478 warning "No harddisks found"
480 for dev in $devices; do
481 debug "$SFDISK will try to backup partition tables for device $dev"
482 [ -b $dev ] || continue
485 outputfile=${partitionsfile//__star__/$label}
486 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
487 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
488 if [ $? -ne 0 ]; then
489 warning "The partition table for $dev could not be saved."
493 if [ "$dohwinfo" == "yes" ]; then
494 debug "Using $HWINFO to get all available disk information"
495 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
496 $HWINFO --disk >> $hardwarefile