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
53 getconf partitions yes
54 getconf partitionsfile /var/backups/partitions.__star__.txt
57 getconf hardwarefile /var/backups/hardware.txt
60 getconf sysreportfile /var/backups/sysreport.txt
62 getconf SFDISK `which sfdisk`
63 getconf HWINFO `which hwinfo`
64 getconf sfdisk_options ""
65 getconf hwinfo_options ""
67 # See if vservers are configured
69 if [ $vservers_are_available = yes ]
71 info "vserver method enabled"
75 ## PACKAGES ##############################
78 # here we grab a list of the packages installed and removed.
81 if [ "$packages" == "yes" ]; then
82 if [ $usevserver = yes ]
84 nodpkg="lost+found|ARCHIVES"
85 info "vserver root directory set to: $VROOTDIR"
86 for vserver in $found_vservers
88 info "examining vserver: $vserver"
89 running=`$VSERVERINFO $vserver RUNNING`
90 if [ "$running" = "1" ]; then
91 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
92 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
93 nodpkg="$nodpkg|$vserver"
96 warning "vserver $vserver is not running, skipping installed packages report."
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 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
115 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
119 # We want to perform this on the host as well
120 if [ "$packages" == "yes" ]; then
121 debug "$packagemgr $packagemgroptions > $packagesfile"
122 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
126 ## System report ##############################
129 # here we grab a bunch of system stuff for a report
134 HASHES="#################################################################"
135 DASHES="-----------------------------------------------------------------"
137 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
141 echo $HASHES >> $sysreportfile
142 echo "# $STATUS" >> $sysreportfile
143 echo $HASHES >> $sysreportfile
145 echo "file: $1" >> $sysreportfile
146 echo $DASHES >> $sysreportfile
147 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
150 echo "directory: $1" >> $sysreportfile
151 echo $DASHES >> $sysreportfile
152 for file in `find $1 -maxdepth 3 -noleaf -type f`
157 echo $DASHES >> $sysreportfile
161 echo $HASHES >> $sysreportfile
162 echo "# $STATUS" >> $sysreportfile
163 echo $HASHES >> $sysreportfile
164 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
168 STATUS="Determining $os version:"
171 STATUS="Determinding your current hostname: "
172 catifexec "/bin/hostname"
174 STATUS="Getting the date:"
175 catifexec "/bin/date"
177 STATUS="Checking your systems current uptime and load average:"
178 catifexec "/usr/bin/uptime"
180 STATUS="Checking available memory:"
181 catifexec "/usr/bin/free"
183 STATUS="Checking free disk space:"
184 catifexec "/bin/df" "-al"
186 STATUS="Collecting what services run at what run level:"
187 if [ $os = "redhat" ]; then
188 catifexec "/sbin/chkconfig --list"
189 STATUS="Collecting information about /etc/rc.d:"
190 catiffile "/bin/ls /etc/rc.d/rc*.d/"
192 elif [ $os = "debian" ]; then
193 for level in 0 1 2 3 4 5 6 S; do
194 echo "Level: $level" >> $sysreportfile
195 for f in /etc/rc${level}.d/*; do
196 # Remove /etc/Knn or Snn from beginning
197 ff=$(echo $f | sed 's_/etc/rc..d/[KS][0-9][0-9]__')
198 if [ $f != $ff ]; then
199 echo $ff >> $sysreportfile
202 echo "" >> $sysreportfile
206 STATUS="Getting bootloader information:"
207 catifexec "/bin/ls -alR /boot"
209 # This covers sparc, alpha, and intel (respectively)
210 # updated for grub -mpg
211 if [ -f /etc/silo.conf ]; then
212 STATUS="Collecting information about the boot process (silo):"
213 catiffile "/etc/silo.conf"
215 if [ -f /etc/milo.conf ]; then
216 STATUS="Collecting information about the boot process (milo):"
217 catiffile "/etc/milo.conf"
219 if [ -f /etc/lilo.conf ]; then
220 STATUS="Collecting information about the boot process (lilo):"
221 catiffile "/etc/lilo.conf"
222 catifexec "/sbin/lilo -q"
224 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
225 STATUS="Collecting information about the boot process (grub.conf):"
226 catiffile "/boot/grub/grub.conf"
227 STATUS="Collecting information about the boot process (grub.map):"
228 catiffile "/boot/grub/device.map"
230 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
231 STATUS="Gathering information on cluster setup"
233 if [ -f /etc/cluster.conf ] ; then
234 catiffile "/etc/cluster.conf"
237 if [ -f /etc/cluster.xml ] ; then
238 catiffile "/etc/cluster.xml"
242 STATUS="Gathering sysctl information (sysctl -a):"
243 catiffile "sysctl -a 2>/dev/null"
244 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
245 catiffile "/etc/sysctl.conf"
247 STATUS="Gathering IP information (/sbin/ifconfig):"
248 catifexec "/sbin/ifconfig -a"
250 STATUS="Gathering additional IP information (/bin/ip addr list):"
251 catifexec "/bin/ip addr list"
253 STATUS="Checking network routes:"
254 catifexec "/sbin/route -n"
256 STATUS="Collecting Name Service Switch config information:"
257 catiffile "/etc/nsswitch.conf"
259 STATUS="Collecting information about system authentication (pam):"
260 catiffile "/etc/pam.conf"
261 catiffile "/etc/pam.d"
264 echo "Getting information about the kernel."
266 STATUS="Getting kernel version:"
267 catifexec "/bin/uname" "-a"
268 STATUS="Checking module information:"
269 catifexec "/sbin/lsmod"
270 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
272 STATUS="Checking module information $x:"
273 catifexec "/sbin/modinfo $x"
276 STATUS="Currently getting ksysms information:"
277 catifexec "/sbin/ksyms"
279 STATUS="Gathering information about your filesystems:"
280 catiffile "/proc/filesystems"
282 STATUS="Gathering information about your system stat:"
283 catiffile "/proc/stat"
285 STATUS="Gathering information about your partitions:"
286 catiffile "/proc/partitions"
288 STATUS="Gathering information about your ksysms:"
289 catiffile "/proc/ksyms"
291 STATUS="Gathering information about slabinfo:"
292 catiffile "/proc/slabinfo"
294 # Added support to cover for the new modules.conf layout in Red Hat 7
295 STATUS="Collecting information regarding kernel modules"
297 catiffile "/lib/modules/$VER/modules.dep"
298 if [ -f /etc/conf.modules ]; then
299 STATUS="Collecting information regarding kernel modules (conf.modules)"
300 catiffile "/etc/conf.modules"
302 if [ -f /etc/modules.conf ]; then
303 STATUS="Collecting information regarding kernel modules (modules.conf)"
304 catiffile "/etc/modules.conf"
306 if [ -f /etc/modprobe.conf ]; then
307 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
308 catiffile "/etc/modprobe.conf"
312 if [ -x /usr/sbin/dkms ] ; then
313 STATUS="Gathering current status of modules, versions and kernels (dkms):"
314 catifexec "/usr/sbin/dkms" "status"
317 if [ -f /etc/sysconfig/isdncard ] ; then
318 STATUS="Gathering information about ISDN:"
319 catiffile "/etc/sysconfig/isdncard"
322 STATUS="Collecting information from the proc directory:"
323 catiffile "/proc/pci"
325 STATUS="Getting kernel command line"
326 catiffile "/proc/cmdline"
328 STATUS="Gathering information about your CPU:"
329 catiffile "/proc/cpuinfo"
331 STATUS="Gathering information about your Ram:"
332 catiffile "/proc/meminfo"
334 STATUS="Gathering information about your ioports:"
335 catiffile "/proc/ioports"
337 STATUS="Gathering information about your interrupts:"
338 catiffile "/proc/interrupts"
340 STATUS="Gathering information about your scsi devices:"
341 catiffile "/proc/scsi"
343 STATUS="Gathering information about your dma:"
344 catiffile "/proc/dma"
346 STATUS="Gathering information about your devices (/proc/devices):"
347 catiffile "/proc/devices"
349 STATUS="Gathering information about your rtc:"
350 catiffile "/proc/rtc"
352 STATUS="Gathering information about your ide drivers:"
353 catiffile "/proc/ide"
355 STATUS="Gathering information about your bus:"
357 catiffile "/proc/bus"
360 echo "Getting disk and filesystem information."
363 STATUS="Collecting information from /etc/fstab:"
364 catiffile "/etc/fstab"
366 STATUS="Collecting disk partition information:"
369 STATUS="Checking mounted file systems (mount) "
370 catifexec "/bin/mount"
372 STATUS="Checking mounted file systems (/proc/mounts)"
373 catiffile "/proc/mounts"
375 STATUS="Collecting Software RAID information (/proc/mdstat)"
376 catiffile "/proc/mdstat"
378 STATUS="Collecting Software RAID information (/etc/raidtab)"
379 catiffile "/etc/raidtab"
381 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
382 catiffile "/etc/mdadm.conf"
384 STATUS="Collecting Automount information (auto.master)"
385 catiffile "/etc/auto.master"
387 STATUS="Collecting Automount information (auto.misc)"
388 catiffile "/etc/auto.misc"
390 STATUS="Collecting Automount information (auto.net)"
391 catiffile "/etc/auto.net"
393 STATUS="Collecting LVM information:"
394 if [ $os = "redhat" ]; then
395 catifexec "/usr/sbin/vgdisplay" "-vv"
396 elif [ $os = "debian" ]; then
397 catifexec "/sbin/vgdisplay" "-vv"
400 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
401 catiffile "/etc/stinit.def"
403 if [ -x /sbin/lsusb ] ; then
404 STATUS="Collecting USB devices list (lsusb):"
405 catifexec "/sbin/lsusb"
408 if [ -x /usr/bin/lshal ] ; then
409 STATUS="Collecting global devices list (lshal):"
410 catifexec "/usr/bin/lshal"
414 STATUS="Gathering information on SELinux setup"
415 catifexec "/usr/bin/selinuxconfig"
416 catifexec "/usr/sbin/sestatus"
417 if [ $os = "redhat" ]; then
418 catifexec "rpm" "-q -V selinux-policy-targeted"
419 catifexec "rpm" "-q -V selinux-policy-strict"
422 if [ $usevserver = yes ]; then
423 STATUS="Gathering vserver information"
424 catiffile "/proc/virtual"
427 if [ "$partitions" == "yes" ]; then
428 if [ ! -x "$SFDISK" ]; then
429 warning "can't find sfdisk, skipping sfdisk report."
432 if [ ! -x "$HWINFO" ]; then
433 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."
446 ## PARTITIONS #############################
448 # here we use sfdisk to dump a listing of all the partitions.
449 # these files can be used to directly partition a disk of the same size.
451 if [ "$partitions" == "yes" ]; then
452 devices=`$HWINFO --disk | grep "Device File" | cut -d\ -f5`
453 for dev in $devices; do
454 [ -b $dev ] || continue
457 outputfile=${partitionsfile//__star__/$label}
458 debug "$SFDISK $sfdisk_options -d $dev > $outputfile"
459 $SFDISK $sfdisk_options -d $dev > $outputfile
463 ## HARDWARE #############################
466 # here we use hwinfo to dump a table listing all the
467 # information we can find on the hardware of this machine
470 if [ "$hardware" == "yes" ]; then
471 if [ -f $hardwarefile ]; then
475 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
476 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
477 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
478 for flag in cpu network disk bios pci; do
479 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
480 $HWINFO --$flag >> $hardwarefile