Grabb Info


Princip: Skript pro souhrnný sběr informaci o daném stroji

Přímo zde vidíte náhled scriptu a ještě jeho kopie ke stažení v gzipu.

    1 #!/bin/bash
    2 #
    3 # Description: Grabb information from PC
    4 # Author: Petr (DotaZ) Jakubec (c) 2007-2010
    5 # Contact: grabb_info _at_ jakubcovi _dot_ info
    6 # Version: Release 0.1.1 public
    7 # Licence: public domain
    8 
    9 
   10 
   11 # Path for data backup:
   12 CESTA="/var/backup/`hostname`-info"
   13 
   14 ## Checking for needed binaries
   15 binaries="date dd fdisk sfdisk dpkg ifconfig netstat iptables-save ip6tables-save route lshw dmidecode lspci df lsmod lsof sysv-rc-conf ps tar rm rmdir"
   16 for bin in $binaries; do
   17   $(which $bin 1>/dev/null 2>&1)
   18   if [ "$?" -eq 1 ]; then
   19     echo -e "$bin" $end_style $red_style" not found in \$PATH. This script may not work..."
   20     exit 1
   21   fi
   22 done
   23 
   24 
   25 # Create dir "hostame-info"
   26 if [ ! -d $CESTA ]
   27 	then
   28 		/bin/mkdir $CESTA &>/dev/null
   29 fi
   30 
   31 if [ ! -d $CESTA2 ]
   32 	then
   33 		/bin/mkdir $CESTA2 &>/dev/null
   34 fi
   35 
   36 
   37 # subdir create "YYYY-MM-DD"
   38 if [ ! -d $CESTA/`date +%Y-%m-%d`/ ]
   39 	then
   40 		/bin/mkdir $CESTA/`date +%Y-%m-%d` &>/dev/null
   41 fi
   42 
   43 # MBR backup :: copy mbr record from first HDD (on /dev/hda)
   44 echo -n " * MBR backup         "
   45 	/bin/dd if=/dev/hda of=$CESTA/`date +%Y-%m-%d`/hda.mbr bs=512 count=1 &>/dev/null
   46 echo -e "\033[092m READY \033[0m"
   47  # Rescue MBR (MBR only, other is OS loader):
   48  # dd  if=$CESTA/`date +%Y-%m-%d`/hda.mbr  of=/dev/hda  bs=1 count=64 skip=446 seek=446
   49  # and ... restart
   50 
   51 echo -n " * Disk snapshoot     "
   52 	/sbin/fdisk -l > $CESTA/`date +%Y-%m-%d`/fdisk_snapshoot.txt
   53 	#dump partitions:
   54 	/sbin/sfdisk -d /dev/hd[abd] > $CESTA/`date +%Y-%m-%d`/sfdisk_snapshoot-hdx.txt 2>/dev/null
   55 	/sbin/sfdisk -d /dev/sd[abcd] > $CESTA/`date +%Y-%m-%d`/sfdisk_snapshoot-sdx.txt 2>/dev/null
   56 	# obnoveni part. table: "sfdisk /dev/hda < sfdisk_snapshoot.txt"
   57 echo -e "\033[092m READY \033[0m"
   58 
   59 echo -n " * DEBs selections    "
   60 	/usr/bin/dpkg -l >>$CESTA/`date +%Y-%m-%d`/package-info.txt
   61 	/usr/bin/dpkg --get-selections >>$CESTA/`date +%Y-%m-%d`/package-select.txt
   62 	# Rescue: dpkg --set-selections <package-select.txt
   63 	/usr/bin/debsums -as &>$CESTA/`date +%Y-%m-%d`/debsums-as.txt
   64 echo -e "\033[092m READY \033[0m"
   65 
   66 # HISTORY
   67 echo -n " * HISTORY summary    "
   68 	cp /root/.bash_history $CESTA/`date +%Y-%m-%d`/root.history.txt
   69 	cp /root/.mc/history $CESTA/`date +%Y-%m-%d`/root.history-mc.txt
   70 echo -e "\033[092m READY \033[0m"
   71 
   72 # IFCONFIG
   73 echo -n " * NIC summary        "
   74 	/sbin/ifconfig >$CESTA/`date +%Y-%m-%d`/ifconfig.txt
   75 	/usr/bin/lsof -nP -i >$CESTA/`date +%Y-%m-%d`/lsof.txt
   76 	/bin/netstat -a >$CESTA/`date +%Y-%m-%d`/netstat-all.txt
   77 	/bin/netstat -r >$CESTA/`date +%Y-%m-%d`/netstat-route.txt
   78 	/bin/netstat -s >$CESTA/`date +%Y-%m-%d`/netstat-stat.txt
   79 	/sbin/iptables-save >$CESTA/`date +%Y-%m-%d`/iptables.txt
   80 	/sbin/ip6tables-save >$CESTA/`date +%Y-%m-%d`/ip6tables.txt 2>/dev/null
   81 	/sbin/route -n > $CESTA/`date +%Y-%m-%d`/route.txt
   82 echo -e "\033[092m READY \033[0m"
   83 
   84 # LSHW
   85 echo -n " * HW summary         "
   86 	/usr/bin/lshw &>$CESTA/`date +%Y-%m-%d`/lshw.txt
   87 	/usr/sbin/dmidecode >$CESTA/`date +%Y-%m-%d`/dmidecode.txt
   88 	/usr/bin/lspci -vv > $CESTA/`date +%Y-%m-%d`/lspci.txt
   89 	/bin/df -h > $CESTA/`date +%Y-%m-%d`/df.txt
   90 	/bin/lsmod > $CESTA/`date +%Y-%m-%d`/lsmod.txt
   91 	cp /boot/grub/menu.lst $CESTA/`date +%Y-%m-%d`/boot_grub-menu.lst.txt
   92 	/sbin/apcaccess status SERVER:3551 > $CESTA/`date +%Y-%m-%d`/ups-status.txt
   93 echo -e "\033[092m READY \033[0m"
   94 
   95 # CHKCONFIG
   96 echo -n " * SysV service sum   "
   97 	/usr/sbin/sysv-rc-conf --list > $CESTA/`date +%Y-%m-%d`/sysv-rc-list.txt
   98 	/bin/ps -elyjH >$CESTA/`date +%Y-%m-%d`/ps.txt
   99 echo -e "\033[092m READY \033[0m"
  100 
  101 
  102 echo -n " * PACKAGE create     "
  103 	/bin/tar -czf $CESTA/`date +%Y-%m-%d`-info.tar.gz --ignore-failed-read $CESTA/`date +%Y-%m-%d`/*.txt $CESTA/`date +%Y-%m-%d`/*.mbr &>/dev/null &&
  104 	rm -f $CESTA/`date +%Y-%m-%d`/*.txt $CESTA/`date +%Y-%m-%d`/*.mbr
  105 	rmdir $CESTA/`date +%Y-%m-%d`/
  106 echo -e "\033[092m READY \033[0m"
  107 
  108 #echo "============================"
  109 # EOF ##############################

Petr Jakubec © 2010