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 nodpkg="$nodpkg|$vserver"
101 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
102 warning "can't find ${packagemgr}, skipping installed packages report."
108 if [ "$packages" == "yes" ]; then
109 if [ $usevserver = yes ]
111 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
113 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
114 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
118 # We want to perform this on the host as well
119 if [ "$packages" == "yes" ]; then
120 debug "$packagemgr $packagemgroptions > $packagesfile"
121 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
125 ## System report ##############################
128 # here we grab a bunch of system stuff for a report
133 HASHES="#################################################################"
134 DASHES="-----------------------------------------------------------------"
136 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
140 echo $HASHES >> $sysreportfile
141 echo "# $STATUS" >> $sysreportfile
142 echo $HASHES >> $sysreportfile
144 echo "file: $1" >> $sysreportfile
145 echo $DASHES >> $sysreportfile
146 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
149 echo "directory: $1" >> $sysreportfile
150 echo $DASHES >> $sysreportfile
151 for file in `find $1 -maxdepth 3 -noleaf -type f`
156 echo $DASHES >> $sysreportfile
160 echo $HASHES >> $sysreportfile
161 echo "# $STATUS" >> $sysreportfile
162 echo $HASHES >> $sysreportfile
163 $1 >> $sysreportfile 2>&1 || info "executing of $1 failed"
167 STATUS="Determining $os version:"
170 STATUS="Determinding your current hostname: "
171 catifexec "/bin/hostname"
173 STATUS="Getting the date:"
174 catifexec "/bin/date"
176 STATUS="Checking your systems current uptime and load average:"
177 catifexec "/usr/bin/uptime"
179 STATUS="Checking available memory:"
180 catifexec "/usr/bin/free"
182 STATUS="Checking free disk space:"
183 catifexec "/bin/df" "-al"
185 STATUS="Collecting what services run at what run level:"
186 if [ $os = "redhat" ]; then
187 catifexec "/sbin/chkconfig --list"
188 STATUS="Collecting information about /etc/rc.d:"
189 catiffile "/bin/ls /etc/rc.d/rc*.d/"
191 elif [ $os = "debian" ]; then
192 for level in 0 1 2 3 4 5 6 S; do
193 echo "Level: $level" >> $sysreportfile
194 for f in /etc/rc${level}.d/*; do
195 # Remove /etc/Knn or Snn from beginning
196 ff=$(echo $f | sed 's_/etc/rc..d/[KS][0-9][0-9]__')
197 if [ $f != $ff ]; then
198 echo $ff >> $sysreportfile
201 echo "" >> $sysreportfile
205 STATUS="Getting bootloader information:"
206 catifexec "/bin/ls -alR /boot"
208 # This covers sparc, alpha, and intel (respectively)
209 # updated for grub -mpg
210 if [ -f /etc/silo.conf ]; then
211 STATUS="Collecting information about the boot process (silo):"
212 catiffile "/etc/silo.conf"
214 if [ -f /etc/milo.conf ]; then
215 STATUS="Collecting information about the boot process (milo):"
216 catiffile "/etc/milo.conf"
218 if [ -f /etc/lilo.conf ]; then
219 STATUS="Collecting information about the boot process (lilo):"
220 catiffile "/etc/lilo.conf"
221 catifexec "/sbin/lilo -q"
223 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
224 STATUS="Collecting information about the boot process (grub.conf):"
225 catiffile "/boot/grub/grub.conf"
226 STATUS="Collecting information about the boot process (grub.map):"
227 catiffile "/boot/grub/device.map"
229 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
230 STATUS="Gathering information on cluster setup"
232 if [ -f /etc/cluster.conf ] ; then
233 catiffile "/etc/cluster.conf"
236 if [ -f /etc/cluster.xml ] ; then
237 catiffile "/etc/cluster.xml"
241 STATUS="Gathering sysctl information (sysctl -a):"
242 catiffile "sysctl -a 2>/dev/null"
243 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
244 catiffile "/etc/sysctl.conf"
246 STATUS="Gathering IP information (/sbin/ifconfig):"
247 catifexec "/sbin/ifconfig -a"
249 STATUS="Gathering additional IP information (/bin/ip addr list):"
250 catifexec "/bin/ip addr list"
252 STATUS="Checking network routes:"
253 catifexec "/sbin/route -n"
255 STATUS="Collecting Name Service Switch config information:"
256 catiffile "/etc/nsswitch.conf"
258 STATUS="Collecting information about system authentication (pam):"
259 catiffile "/etc/pam.conf"
260 catiffile "/etc/pam.d"
263 echo "Getting information about the kernel."
265 STATUS="Getting kernel version:"
266 catifexec "/bin/uname" "-a"
267 STATUS="Checking module information:"
268 catifexec "/sbin/lsmod"
269 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
271 STATUS="Checking module information $x:"
272 catifexec "/sbin/modinfo $x"
275 STATUS="Currently getting ksysms information:"
276 catifexec "/sbin/ksyms"
278 STATUS="Gathering information about your filesystems:"
279 catiffile "/proc/filesystems"
281 STATUS="Gathering information about your system stat:"
282 catiffile "/proc/stat"
284 STATUS="Gathering information about your partitions:"
285 catiffile "/proc/partitions"
287 STATUS="Gathering information about your ksysms:"
288 catiffile "/proc/ksyms"
290 STATUS="Gathering information about slabinfo:"
291 catiffile "/proc/slabinfo"
293 # Added support to cover for the new modules.conf layout in Red Hat 7
294 STATUS="Collecting information regarding kernel modules"
296 catiffile "/lib/modules/$VER/modules.dep"
297 if [ -f /etc/conf.modules ]; then
298 STATUS="Collecting information regarding kernel modules (conf.modules)"
299 catiffile "/etc/conf.modules"
301 if [ -f /etc/modules.conf ]; then
302 STATUS="Collecting information regarding kernel modules (modules.conf)"
303 catiffile "/etc/modules.conf"
305 if [ -f /etc/modprobe.conf ]; then
306 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
307 catiffile "/etc/modprobe.conf"
311 if [ -x /usr/sbin/dkms ] ; then
312 STATUS="Gathering current status of modules, versions and kernels (dkms):"
313 catifexec "/usr/sbin/dkms" "status"
316 if [ -f /etc/sysconfig/isdncard ] ; then
317 STATUS="Gathering information about ISDN:"
318 catiffile "/etc/sysconfig/isdncard"
321 STATUS="Collecting information from the proc directory:"
322 catiffile "/proc/pci"
324 STATUS="Getting kernel command line"
325 catiffile "/proc/cmdline"
327 STATUS="Gathering information about your CPU:"
328 catiffile "/proc/cpuinfo"
330 STATUS="Gathering information about your Ram:"
331 catiffile "/proc/meminfo"
333 STATUS="Gathering information about your ioports:"
334 catiffile "/proc/ioports"
336 STATUS="Gathering information about your interrupts:"
337 catiffile "/proc/interrupts"
339 STATUS="Gathering information about your scsi devices:"
340 catiffile "/proc/scsi"
342 STATUS="Gathering information about your dma:"
343 catiffile "/proc/dma"
345 STATUS="Gathering information about your devices (/proc/devices):"
346 catiffile "/proc/devices"
348 STATUS="Gathering information about your rtc:"
349 catiffile "/proc/rtc"
351 STATUS="Gathering information about your ide drivers:"
352 catiffile "/proc/ide"
354 STATUS="Gathering information about your bus:"
356 catiffile "/proc/bus"
359 echo "Getting disk and filesystem information."
362 STATUS="Collecting information from /etc/fstab:"
363 catiffile "/etc/fstab"
365 STATUS="Collecting disk partition information:"
368 STATUS="Checking mounted file systems (mount) "
369 catifexec "/bin/mount"
371 STATUS="Checking mounted file systems (/proc/mounts)"
372 catiffile "/proc/mounts"
374 STATUS="Collecting Software RAID information (/proc/mdstat)"
375 catiffile "/proc/mdstat"
377 STATUS="Collecting Software RAID information (/etc/raidtab)"
378 catiffile "/etc/raidtab"
380 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
381 catiffile "/etc/mdadm.conf"
383 STATUS="Collecting Automount information (auto.master)"
384 catiffile "/etc/auto.master"
386 STATUS="Collecting Automount information (auto.misc)"
387 catiffile "/etc/auto.misc"
389 STATUS="Collecting Automount information (auto.net)"
390 catiffile "/etc/auto.net"
392 STATUS="Collecting LVM information:"
393 if [ $os = "redhat" ]; then
394 catifexec "/usr/sbin/vgdisplay" "-vv"
395 elif [ $os = "debian" ]; then
396 catifexec "/sbin/vgdisplay" "-vv"
399 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
400 catiffile "/etc/stinit.def"
402 if [ -x /sbin/lsusb ] ; then
403 STATUS="Collecting USB devices list (lsusb):"
404 catifexec "/sbin/lsusb"
407 if [ -x /usr/bin/lshal ] ; then
408 STATUS="Collecting global devices list (lshal):"
409 catifexec "/usr/bin/lshal"
413 STATUS="Gathering information on SELinux setup"
414 catifexec "/usr/bin/selinuxconfig"
415 catifexec "/usr/sbin/sestatus"
416 if [ $os = "redhat" ]; then
417 catifexec "rpm" "-q -V selinux-policy-targeted"
418 catifexec "rpm" "-q -V selinux-policy-strict"
421 if [ $usevserver = yes ]; then
422 STATUS="Gathering vserver information"
423 catiffile "/proc/virtual"
426 if [ "$partitions" == "yes" ]; then
427 if [ ! -x "$SFDISK" ]; then
428 warning "can't find sfdisk, skipping sfdisk report."
431 if [ ! -x "$HWINFO" ]; then
432 warning "can't find hwinfo, skipping partition report."
437 if [ "$hardware" == "yes" ]; then
438 if [ ! -x "$HWINFO" ]; then
439 warning "can't find hwinfo, skipping hardware report."
445 ## PARTITIONS #############################
447 # here we use sfdisk to dump a listing of all the partitions.
448 # these files can be used to directly partition a disk of the same size.
450 if [ "$partitions" == "yes" ]; then
451 devices=`$SFDISK -l | grep "^Disk /dev" | cut -d/ -f2,3 | cut -d: -f1`
452 if [ "$devices" == "" ]; then
453 warning "No harddisks found"
455 for dev in $devices; do
456 [ -b $dev ] || continue
459 outputfile=${partitionsfile//__star__/$label}
460 debug "$SFDISK $sfdisk_options -d /$dev > $outputfile"
461 $SFDISK $sfdisk_options -d /$dev > $outputfile
465 ## HARDWARE #############################
468 # here we use hwinfo to dump a table listing all the
469 # information we can find on the hardware of this machine
472 if [ "$hardware" == "yes" ]; then
473 if [ -f $hardwarefile ]; then
477 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
478 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
479 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
480 for flag in cpu network disk bios pci; do
481 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
482 $HWINFO --$flag >> $hardwarefile