#!/bin/bash
#
# make system documentation
#
## This version is intended to run on SLES8/9/10-systems (ia32/64+IA64) !!!
## see man page sysdoc(8) for more infos
#
# (cr) 2005 by csh @ FSC PS BLN
#
#
# Changelog of sysdoc. You will find the most recent version at the buttom of this list.
#
#  csh   0.1   (17.06.2005) Initial Version
#  csh   0.2   (21.06.2005) hostname in tar-filename
#                           + ddm, init.d, boot ... infos
#  csh   0.3   (21.06.2005) check if FSC-WS is installed w/ report
#  csh   0.4   (23.06.2005) corrected DDM, boot
#  csh   0.5   (23.06.2005) added PCL-PCS-output
#  csh   0.6   (25.06.2005) added "-V" version info parameter
#  csh   0.61  (25.06.2005) some systems have problems w/ >> &>1 :-(
#  csh   0.62  (25.06.2005) copy  complete /etc/PRIMECLUSTER 
#  csh   0.63  (12.09.2005) include ~/doc
#  csh   0.64  (12.09.2005) also copy hosts&fstab (no comments in sitar :-()
#  csh   0.65  (02.11.2005) for SIS: check -e against DIR not conf-file
#  csh   0.66  (08.11.2005) for some files in /etc copy history also (e.g: hosts*)
#  csh   0.67  (11.11.2005) do ..scan on LVM 
#  csh   0.68  (15.11.2005) incl. /etc/services
#  csh   0.70  (14.12.2005) first rel w/ kernel 2.6 support (lvm)
#  csh   0.71  (15.12.2005) sitar 2.4(file) & 2.6(dir) differ :-(
#  csh   0.80  (06.02.2006) whole job in one file w/ function core(=old mksysdok)
#                           some typos, also copy *omsg
#  csh   0.81  (17.02.2006) added infos about filesystems,issue,profile
#  csh   0.82  (13.04.2006) added tune2fs for LVM filesystems
#                           + report logfilename
#  csh   0.83  (08.05.2006) added tune2fs support for 2.4 systems (auto)
#  csh   0.90  (13.07.2006) added mount infos from proc (fs-type)
#                           added ifconfig,netstat,ethtool infos
#                           added /proc/scsi infos
#                           added lspci infos
#                           group most *txt-files under /doc
#  csh   0.91  (13.07.2006) added EMCpowerpath infos 
#                           also include errors messages of core function to log file
#  csh   0.92  (18.07.2006) added xientd configs; system infos (uname,uptime...)     
#  csh   0.930 (27.10.2006) added snmp retrieval (MIBII and SV) 
#                           added recent SV-logs
#                           version numbers 0.9xx (add. subnumber)
#  csh   0.940 (17.11.2006) from now on sysdoc is distributed as rpm-package 
#                           (incl. man page and doc's)
#  csh   0.941 (20.11.2006) corrected system section output
#  csh   0.942 (01.12.2006) corrected retrieving of community for smnp-output (\t := " ")
#                           (using "public" as last resort)
#  csh   0.950 (21.01.2007) new infos about system (lsdev, ps, sysconfig-files, proc/rd, SuSErelease)
#                           added some /proc infos
#                           added some infos specific to ia64 (IPF) architecture (parted)
#                           added next level of sitar-infos (which is not part of all distris)
#                           enhanced info about snmp fault
#  csh   0.951 (23.01.2007) new info about rpm-installed packages in doc/packages
#                           added infos form proc (cpu+mem)
#                           added infos from /etc (printcap;hosts;inittab;crontab,chkconfig)
#  csh   0.952 (28.01.2007) corrected partition info by parted if system ownes DAC960 controller(s)
#                           enhanced output of filesystem/partitions-info
#  csh   0.953 (20.02.2007) parted has Problems w/ multipaths (if hidden) -> drop code :-( (temp)
#                           enhanced output of lspci (now added -n)
#                           additional info about devices from /sys/class/scsi_host
#                           additional info about network devices (bonding + vlan from /proc)
#                           new section: /sys
#  csh   0.954 (24.02.2007) reactivated parted-code w/ ia64-test
#                           include /proc/config.gz
#                           added /sys/devices (for driver-info)
#                           added snmp-info from SVlist
#  csh   0.960 (05.03.2007) improved success at fsc-mib-retrieval
#                           added support for PRIMERGY BladeFrame cBlades
#  csh   0.961 (15.03.2007) copy README to tgz
#                           added all sys/* into sys.tgz (fc_... !)
#  csh   0.962 (20.03.2007) copy inittab to tgz
#                           output of system commands in doc-section (lvm,network,system...) is given to seperat files
#  csh   0.963 (09.04.2007) added new sys infos (sysctl, hwinfo, ulimit, pam.d) 
#                           test for existing /sys before retrieving from (otherwise it will tar / to tgz ;-)
#                           reduced hwinfo to "std"-devices (no braille, tv,.....)
#                           added iptables output to network section
#  csh   0.964 (09.04.2007) added further infos from cBlades on BladeFrame's
#  csh   0.965 (19.04.2007) corrected handling of /etc
#                           added FlexFrame depended configs /var/FlexFrame
#  csh   0.970 (25.04.2007) the ...log file is now put into the "tgz" - so there is only one file as result,
#                           which contains ALL information 
#                           sysdoc reports start-time (@begin) and used time (@end) for infomation (+time)
#                           separate files for LICENSE and COPYING, added download+license-info to help
#                           internal: packing+cleaning-code moved from core-function to body
#  csh   0.971 (02.05.2007) the run-time is also recorded in log-file (wraped core function due to internal time)
#                           copy all *conf* and *tab* files from /etc
#                           most infos in /proc (incl subdirs but w/o process-subtrees [1-9]*)
#                           nfs runtime infos (nfsstat;showmount in the system-section)
#                           analyse syslog-conf(s) for logfile to copy into "tgz"
#  csh   0.972 (02.05.2007) fixed logfiles-section (different handling for syslogd & syslogd-ng)
#                           +report syslog-conf-files
#                           fixed proc-section (exclude acpi/event....)
#  csh   0.973 (08.05.2007) some adoptions to SLES8 (correct handling /proc/partitions -> parted)
#                           excluded "event" from proc-file-collection
#                           added collection of sar-files (incl. bin-file) in new section
#                           added mpstat, vmstat, iostat (new parameter)
#                           added RELEASE-info to rpm_packages.txt
#  csh   0.974 (10.05.2007) improved pci-infos (+ -vvv and -t (treeview))
#                           added ntp-info + vmstat-info in system
#  csh   0.975 (21.05.2007) improved syslog handling (report found active syslog.conf and use this one only)
#                           added infos about multipathing (DM based) into separate doc/dm-multipath
#  csh   0.980 (11.09.2007) the sysdoc "executable" is now placed in /usr/sbin (better for FF-environments)
#                           rewriten the sections to functions (enable later use for -s (short))
#                           include install date into rpm-report
#  csh   0.981 (16.11.2007) enhancements to BF's (incl. dir /opt/egenera/install)
#                           corrected function calls (missed some ...hwinfo...)
#                           changed cp options to -a (to preserve mod-date)
#                           Architecture (platform) is "noarch" from now on
#  csh   0.982 (17.11.2007) added XEN related info support
#                           fixed proc info exclude (XEN related)
#  csh   0.983 (28.11.2007) fixed placing of xen-infos > /doc/xen 
#                           added Release-nr. to VERSION & man-page
#                           added xen-vm-config-dir to tgz
#                           reactivated /var/log/messages (for old syslog)
#                           fixed placeing PowerPath info > /doc/EMC
#  csh   0.984 (26.01.2008) fixed cBlade-info egenera props         
#                           put a txt-version of man page to /usr/.../doc...
#  csh   0.985 (07.07.2008) fixed sar-Infos (sa* | grep -v sar instead sa.*)
#                           exec sar/sa-collect before copying files
#                           collect last 3 sa*-files (not only last one)
#                           added QLA-infos (via scli)
#                           fixed pam-config collection (find type is now d (not f))
#                           added /etc/securtity
#                           added dmidecode to system
#                           added tmp-SVlist-dir w/ correct snmp-community
#                           added parameter "-c" (cleanup /tmp)
#                           added parameter "-x set,set,set..." (exclude info-sets)
#                           added /etc/SuSEconfig/ - files
#                           added info about calling parameters at start (log)
#                           fixed -c function (exclude actual log file)
#                           added report of deleted files by -c
#                           added SV-Raid infos (if installed)
#                           changed multipath -l to -ll
#  csh   0.986 (19.09.2008) fixed SVlist-handling again (due to hardcoding of .ini-file):
#                           added "patchstr" to patch SVlist-binary in /tmp
#                           added ServerView-status to snmp_info.txt
#                           added SVlist... community-check w/ warning if differs from snmp-system
#                           added /etc/udev 
#                           fixed patchstr binary type to static32 (was ..64) to be comatible w/ most systems
#                           (former substr is now: patchstr  ; "patch" matches function better then "substitute...")
#  csh   0.986 (21.09.2008) R7  added swapinfos (free,swap)
#                               added check for SVlist... (w/ info)
#  csh   0.986 (21.12.2008) R8  fixed snmp community search typo (now [:space:]) 
#                               fixed: exectuting SVlist... only one time    
#  csh   0.986 (22.12.2008) R9  fixed snmp community search typo (now [:space:]) 
#  csh   0.986 (22.12.2008) R8  fixed powerpath infos
#  csh   0.990-1 (01.01.2009) added powerpath registration info
#                             added san -A & showme -l to cBlade-info    
#                             added infos about install repositories (zypper only in this Rel.)
#                             mention Rel. in Version string (CHANGES only)
#                             improved lvm2 infos (added -o +devices & -m)
#                             added blkid info ( e.g. UUID of volume) to /doc/filesystems/volume_info.txt
#                             changed name of system-infos-dir to /doc/system-status (formerly ...system...)
#                             changed location of HW-relevant infos to an own dir (/doc/hw)
#                             changed location of pci infos to the HW-dir (/doc/hw)
#                             added who, pstree system-status info
#                             changed name of dm-multipath info to device-mapper
#                             added ../disk-by* and some other infos to device-mapper
#  csh   0.990-2 (02.01.2009) changed pstree from -U to -A (utf > ascii)
#                             added zypper sl & rug ca to repositories info
#                             changed "not installed" to "not available" in log-output
#  csh   0.991-1 (08.01.2009) added /etc/*.cf (spam&mailer-configs) 
#                             added /etc/postfix
#                             added YaST2logs
#                             added autofs-files
#                             changed location of BF-cblade info to /doc/BladeFrame_cblade
#                             added save-state to BF-cblade info
#  csh   0.991-2 (12.01.2009) added some esh commands to BF-cblade-infos
#  csh   0.991-3 (14.01.2009) added link (www.sysdoc.de) to 1st line of README          
#                             the README.* is also copied from sysdoc's run location (if file exists)
#  csh   0.992-1 (02.05.2009) resolve-links: make sure that files are copied even if they are links (if linked, copy target-dir or -file)
#                             added /etc/HOSTNAME,/etc/shadow
#                             some cosmetics (error-outputs suppressed)
#                             fixed some typos (snmp/SV)
#  csh   0.992-2 (02.05.2009) fixed SVlist...ini handling: be aware of DOS-type w/ ^R
#                             enabled /etc/primecluster in upper or lower cases
#  csh   0.992-3 (02.05.2009) fixed BF-cblade detection
#                             added pool-infos to BF-cblade
#  csh   0.992-4 (02.05.2009) added collection of files AND links in etc-set 
#                             changed filter from *tab* to *tab in etc-set
#  csh   0.992-5 (03.05.2009) fixed BF-cblade detection (typo)
#                             A codename is included w/in the VERSION (-V) : TFAX
#                             included copy of fc_* in sysfs-info
#  csh   0.992-6 (17.06.2009) sysstat: pay attention to x86_64 implementation (lib64)
#  csh   0.992-1st (-12.2010) prerelease: just for evaluation
#  csh   0.993-2 (17.12.2010) FATS : respect new versions of ServerView-RAID (/opt/fujitsu...)
#                             changed /etc/conf's to *conf* but --exclude="gconf" (files&dirs)
#                             changed filesystems: df + -a
#                             added "last"-output to system-status 
#                             fixed network typo "iip"
#                             added sg_map to device info
#                             changed snmpwalk: added -Cc (continue when not increasing)
#                             changed snmpwalk fsc:  >ServerView + complete 231-tree
#                             changed snmpd.conf retrievel from cut -f 9  to cut -d "/" (better for different date presentations)
#                             changes /sys collection: not collecting /sys/kernel (due to infinit time)
#  csh   0.993-3 (22.12.2010) changed sysstat-collect execution to be done w/in extra bash (due to complex cron-job lines)
#                             changed order of license + size in rpm-package info
#  csh   0.993-4 (27.12.2010) changed snmpcollection (-Cc dumps infinit w/ ServerView :-( )
#                             changes repository info to detailed (-d) for suse-zypper
#                             added info for loop-mounts in filesystem-section
#  csh   0.993-5 (16.01.2011) fixed sys-tgz-collection (echo * > ls -1) 
VERSION="0.993-Rel.5 'FATS' (cr) 16.01.2011"
CODENAME=FATS

##############################################################################
#
# global vars
#
TIMESTAMP=$(date +"%Y%m%d-%H%M")
SITARSOLD=/tmp/sitars_old
SITARARCH=$SITARSOLD/${TIMESTAMP}00
SYSDOCDIR=/tmp/sysdoc_$( hostname | cut -d "." -f 1)-$TIMESTAMP
SYSTYPE=$(uname -r|cut -b 1-3)
LOGFILE="/tmp/sysdoc_$( hostname | cut -d "." -f 1)_$(date +"%Y%m%d-%H%M").log"
Community=""
STARTDIR=$(/bin/pwd)


##############################################################################
#
# Tell the user who we are.....
#
function usage() {
    echo ""
    echo "This is \"$0\" script (Version $VERSION)"
    echo ""
    echo "which puts some interesting system informations into a gzipped tar file(tgz)."
    echo "It uses SITAR in the first step to genarate a html-file w/ std infos."
    echo "Within the second step additional informations are gathered:"
    echo "proc, lvm, nfs, Primecluster, boot, DDM, init.d, etc/*conf, syslog,"
    echo "profile.d, PCS, hosts, fstab... (may be more)"
    echo "Also every file in ~/doc will be included (so this is the place"
    echo "to put every non-standard information)."
    echo ""
    echo "Usage: sysdoc [-c] [-h]-[-V] [-x set,set,...]"
    echo "   -c     The option -c (cleanup) will cause a removal of any /tmp/sysdoc*-file"
    echo "   -h     The option -h (or --help) displays help."
    echo "   -V     shows the version of sysdoc (does nothing else)"
    echo "   -x set,...  means  "exclusion" of an info-set (-x ? or -x L gives a list of "
    echo "          valid sets). This option can be used if sysdoc unfortunately hangs "
    echo "          w/in a set (then abort w/ "^C" and restart sysdoc w/ parameters -c -x set)"
    echo ""
    echo "(all important information is put out to the screen and into the log-file)"
    echo ""
    echo "For more information, please have a look at the man page sysdoc(8) and" 
    echo "/usr/share/doc/packages/sysdoc/README (CHANGES,...)" 
    echo ""
    echo "SYSDOC is distibuted under GPL V2 (see COPYING and COPYING) and can be"
    echo "downloaded from http://www.sysdoc.de"
}

function run_sitar() {
 which sitar &> /dev/null
 if [[ $? == 0 ]] ; then
    ls /tmp/*sitar-* &> /dev/null
    if [[ $? == 0 ]] ; then
       echo "old sitar-files exist...."
       ls $SITARSOLD &> /dev/null
       if [[ $? != 0 ]] ; then
          echo "no $SITARSOLD dir exists...creating..."
          mkdir $SITARSOLD
       fi
       echo "...creating ARCH-dir $SITARARCH..."
       mkdir $SITARARCH
       echo -n "...saving old sitar-files..."
       mv /tmp/*sitar-* $SITARARCH
       echo "done"
    fi
 
    echo -n "executing sitar..."
    sitar &> /dev/null
    echo -n "saving..."
    if [[ "$SYSTYPE" = "2.4" ]] ; then 
       mv /tmp/sitar-*html $SYSDOCDIR
    else 
       mv /tmp/sitar-*/*html $SYSDOCDIR
    fi
    rm -r /tmp/*sitar-*
    echo "done"
 else
    echo "..." 
    echo "...sitar not available...skipping !!!  :-(" 
    echo "..." 
 fi
}


function get_proc() {
 echo "---proc---------------------:"
  DIR=proc
  mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
  cd /$DIR
  for d in $(find  [a-z]* -type d | egrep  -v "kcore|kmsg|event|xenbus") ; do
      mkdir -p $SYSDOCDIR/$DIR/$d >> $SYSDOCDIR/doc/proc_info.txt 2>&1
  done
  for d in $(find  [a-z]* -type f | egrep  -v "kcore|kmsg|event|xenbus") ; do
      echo $d >> $SYSDOCDIR/doc/proc_info.txt
      cat $d > $SYSDOCDIR/$DIR/$d 2>$SYSDOCDIR/doc/proc_info.txt
  done
#  cp -av --parents $(find  [a-z]* -type f | egrep  -v "kcore|kmsg|event|xenbus") \
#                   $SYSDOCDIR/$DIR >> $SYSDOCDIR/doc/proc_info.txt 2>&1
 echo "---proc-----------------done!"
}

function get_sysfs() {
 echo "---sysfs--------------------:"
 if [[ "$SYSTYPE" = "2.6" ]] ; then 
    DIR=sys/class
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cd /$DIR
    cp  -a scsi_host scsi_generic scsi_device net fc_* $SYSDOCDIR/$DIR &> /dev/null
    DIR=sys/tgz
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cd /sys
    cp -a $(ls -1 | grep -v kernel) $SYSDOCDIR/$DIR  &> /dev/null
    cd $SYSDOCDIR/$DIR
    tar czf ../sys.tgz * &> /dev/null
    cd ..
    rm -r tgz
 else
    echo ".../sys is only applicable on 2.6 Kernels " 
 fi
 echo "---sysfs----------------done!"
}

function get_lvm() {
 echo "---lvm----------------------:"
 if [[ "$SYSTYPE" = "2.4" ]] ; then 
    echo "...$SYSTYPE..."
    DIR=proc/lvm
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -a /$DIR/* $SYSDOCDIR/$DIR &> /dev/null
    DIR=doc/lvm
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    find /proc/lvm >> $SYSDOCDIR/$DIR/lvm_files.txt
 else
    # should be 2.6 aka SLES9++
    echo "...$SYSTYPE..."
    DIR=doc/lvm2
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    for typ  in "pv" "vg" "lv" ; do
       echo "...${typ}s..."          | tee -a $SYSDOCDIR/$DIR/${typ}_info.txt
       if [[ "$typ" = "pv" ]] ; then 
          ${typ}s                   >>        $SYSDOCDIR/$DIR/${typ}_info.txt
       else
          ${typ}s -o +devices       >>        $SYSDOCDIR/$DIR/${typ}_info.txt
       fi
       echo "...${typ}scan..."       | tee -a $SYSDOCDIR/$DIR/${typ}_info.txt
       ${typ}scan                         >>  $SYSDOCDIR/$DIR/${typ}_info.txt
       echo "...${typ}display..."    | tee -a $SYSDOCDIR/$DIR/${typ}_info.txt
       if [[ "$typ" = "lv" ]] ; then 
          ${typ}display -m                >>  $SYSDOCDIR/$DIR/${typ}_info.txt
       else
          ${typ}display                   >>  $SYSDOCDIR/$DIR/${typ}_info.txt
       fi
    done 
 fi
 echo "---lvm------------------done!"
}

function get_filesystems() {
 echo "---filesystems--------------:"
 DIR=doc/filesystems
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 echo "...partitions..." | tee -a $SYSDOCDIR/$DIR/partitions_info.txt
 fdisk -l >> $SYSDOCDIR/$DIR/partitions_info.txt
 uname -a | grep ia64 &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...partitions (by parted on ia64)..." | tee -a $SYSDOCDIR/$DIR/partitions_info.txt
    for dev in $(cat /proc/partitions | grep -v "#" |tr -s " "| cut -d " " -f 5 | \
                 grep -v '[0-9]' | grep '[a-z]'); do 
       parted -s /dev/$dev print >> $SYSDOCDIR/$DIR/partitions_info.txt
    done
 fi   
 if [[ $(cat /proc/partitions | grep "rd/") ]] ; then
    echo "...partitions (on DAC960 w/ parted)..." | tee -a $SYSDOCDIR/$DIR/partitions_info.txt
    for dev in $(cat /proc/partitions | tr -s " "| cut -d " " -f 5 | grep "rd/" | grep -v  "rd/.*p.*"); do
       parted -s /dev/$dev print >> $SYSDOCDIR/$DIR/partitions_info.txt
    done
 fi
 which blkid &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...blkid..." | tee -a $SYSDOCDIR/$DIR/volume_info.txt
    blkid      >> $SYSDOCDIR/$DIR/volume_info.txt
 else
    echo "...blkid not available...skipping!" | tee -a $SYSDOCDIR/$DIR/volume_info.txt
 fi 
 which vol_id &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...vol_id..." | tee -a $SYSDOCDIR/$DIR/volume_info.txt
    for part in $(fdisk -l | cut -d " " -f 1| grep /); do 
        echo "---$part:" >> $SYSDOCDIR/$DIR/volume_info.txt
        vol_id $part     >> $SYSDOCDIR/$DIR/volume_info.txt
    done   
 else
    echo "...vol_id not available...skipping!" | tee -a $SYSDOCDIR/$DIR/volume_info.txt
 fi 
 which losetup &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...losetup -a..." | tee -a $SYSDOCDIR/$DIR/volume_info.txt
    losetup -a                    >> $SYSDOCDIR/$DIR/losetup_-a.txt
 else
    echo "...losetup not available...skipping!" | tee -a $SYSDOCDIR/$DIR/volume_info.txt
 fi 
 echo "...df..."| tee -a $SYSDOCDIR/$DIR/filesystems_info.txt
 df -a                >> $SYSDOCDIR/$DIR/filesystems_info.txt
 echo "...df -h..."   >> $SYSDOCDIR/$DIR/filesystems_info.txt
 df -ha               >> $SYSDOCDIR/$DIR/filesystems_info.txt
 echo "...mounts..."  >> $SYSDOCDIR/$DIR/filesystems_info.txt
 cat /proc/mounts     >> $SYSDOCDIR/$DIR/filesystems_info.txt
 echo "...tune2fs..."
 for fs in $(fdisk -l | grep "83  Linux" | tr -s " " |cut -d " " -f 1) ; do
     echo "-S----- $fs :" >> $SYSDOCDIR/$DIR/tune2fs_info.txt
     tune2fs -l $fs       >> $SYSDOCDIR/$DIR/tune2fs_info.txt 2>&1
 done 
 if [[ "$SYSTYPE" = "2.6" ]] ; then 
    for fs in $(lvscan | grep "ACTIVE" | cut -d "'" -f 2) ; do
        echo "-L----- $fs :" >> $SYSDOCDIR/$DIR/tune2fs_info.txt
        tune2fs -l $fs       >> $SYSDOCDIR/$DIR/tune2fs_info.txt 2>&1
    done
 else
    for fs in $(lvscan | grep "ACTIVE" |  tr -s " " | tr -d "\"" | cut -d " " -f 4) ; do
        echo "-L----- $fs :" >> $SYSDOCDIR/$DIR/tune2fs_info.txt
        tune2fs -l $fs       >> $SYSDOCDIR/$DIR/tune2fs_info.txt 2>&1
    done
 fi 
 echo "---filesystems----------done!"
}

function get_nfs() {
 echo "---nfs----------------------:"
 DIR=etc
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 cp -a /$DIR/exports  $SYSDOCDIR/$DIR
 echo "---nfs------------------done!"
}

function get_primecluster() {
 echo "---primecluster-------------:"
 DIR=opt/SMAW
 if [[ -e /$DIR ]] ; then
#w#w helperscripts derieved from pcl-scripts
    DIRpcl=$(ls -1 /etc | grep -i primecluster)
    if [[ "$?" == "0" ]] ; then
       DIR=etc/$DIRpcl
       echo "...scripts..."
       mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
       cp -a /$DIR/*  $SYSDOCDIR/$DIR &> /dev/null
    fi
    echo "...SMAWsf..."
    DIR=etc/opt/SMAW/SMAWsf
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -a /$DIR/*  $SYSDOCDIR/$DIR &> /dev/null
    echo "...RMSetc..."
    DIR=opt/SMAW/SMAWRrms/etc
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -a /$DIR/*  $SYSDOCDIR/$DIR &> /dev/null
    echo "...default..."
    DIR=etc/default
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -a /$DIR/*  $SYSDOCDIR/$DIR &> /dev/null
    DIR=etc
    echo "...cf..."
    cp -a /$DIR/cip.cf  $SYSDOCDIR/$DIR/ &> /dev/null
    DIR=doc/PCL4
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
#w# runtime pcs commands
    for cmd  in "hvdisp -a" "hvdisp -h" "hvdisp -m" "hvenv" "wvstat"\
                "sdtool -C" "sdtool -s" "cftool -c" "cftool -n" \
                "ipcs -qmas" ; do
       D=$(echo $cmd |tr " " "_"| tr "/" "%");
       echo "...$cmd..."
       $cmd                                                    &> $SYSDOCDIR/$DIR/$D.txt
    done
#w# which pcsdump &> /dev/null
    if [[ $? == 0 ]] ; then
       echo "...PCS..."
       echo "# --- diags (formerly known as pcsdump) :"  >> $SYSDOCDIR/$DIR/PCL4_info.txt
       #w# pcsdump -f $SYSDOCDIR/$DIR/PCS_dump >> $SYSDOCDIR/$DIR/PCL4_info.txt
    else
       echo "...PCS not available...skipping!" | tee -a $SYSDOCDIR/$DIR/PCL4_info.txt
    fi
    DIR=etc/opt/SMAW/SMAWdtcp 
    if [[ -e /$DIR ]] ; then
       mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
       cp -a /$DIR/*   $SYSDOCDIR/$DIR/ &> /dev/null  
    else
       DIR=doc/PCL4
       mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
       echo "...SIS not available...skipping!" | tee -a $SYSDOCDIR/$DIR/PCL4_info.txt 
    fi   
 else
    DIR=doc/PCL4
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    echo "...PRIMECLUSTER not available...skipping!" | tee -a $SYSDOCDIR/$DIR/PCL4_info.txt
 fi
 echo "---primecluster---------done!"
}

function get_boot() {
 echo "---boot---------------------:"
 DIR=boot/grub
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 ls -lR /$DIR/../* >> $SYSDOCDIR/doc/boot_files.txt
 cp -a /$DIR/menu.lst $SYSDOCDIR/$DIR &> /dev/null
 if [[ $? != 0 ]] ; then
    echo "...no \"menu.lst\" found. Using (e)lilo? (if: see config in /etc)" | tee -a $SYSDOCDIR/doc/boot_files.txt
 fi
 echo "---boot-----------------done!"
}

function get_postfix() {
 echo "---postfix------------------:"
 DIR=etc/postfix
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 cp -a /$DIR/[a-z]*  $SYSDOCDIR/$DIR &> /dev/null
 echo "---postfix--------------done!"
} 

function get_yast2logs() {
 echo "---yast2logs----------------:"
 DIR=var/log/YaST2
 mkdir -p       $SYSDOCDIR/$DIR &> /dev/null
 ls -l /$DIR  > $SYSDOCDIR/$DIR/yast2logs_files.txt
 cp -a /$DIR/*  $SYSDOCDIR/$DIR &> /dev/null
 rm $SYSDOCDIR/$DIR/*-[0-9]*    &> /dev/null
 echo "---yast2logs------------done!"
} 

function get_ddm() {
 echo "---ddm----------------------:"
 DIR=doc/DDM
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 ddm -ml  &> /dev/null
 if [[ $? == 0 ]] ; then
    ddm -l                                                    >> $SYSDOCDIR/$DIR/ddm_info.txt
    ddm -ml                                                   >> $SYSDOCDIR/$DIR/ddm_info.txt
 else
    echo "...DDM-Multipath not available...skipping!"   | tee -a $SYSDOCDIR/$DIR/ddm_info.txt
 fi
 ddm -dl  &> /dev/null
 if [[ $? == 0 ]] ; then
    ddm -dl                                                   >> $SYSDOCDIR/$DIR/ddm_info.txt
 else
    echo "...DDM-DuplexWrite not available...skipping!" | tee -a $SYSDOCDIR/$DIR/ddm_info.txt
 fi
 DIR=etc
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 cp -a /$DIR/ddm.conf $SYSDOCDIR/$DIR  &> /dev/null
 echo "---ddm------------------done!"
}

function get_device-mapper() {
 echo "---device-mapper------------:"
 DIR=doc/device-mapper
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 for cmd  in "dmsetup ls" "ls -l /dev/disk/by-*" "ls -l /dev/mapper" "ls -l /dev/dm*" \
             "multipath -ll" "mdadm -D --scan" \
             ; do
     echo -n "...$cmd"                    | tee -a $SYSDOCDIR/$DIR/device-mapper_info.txt
     which $(echo $cmd | cut -d " " -f 1) &>/dev/null
     if [[ $? == 0 ]]; then
        D=$(echo "$cmd" | tr " " "_" | tr "/" "%" | tr "*" "#");
        echo "..."                        | tee -a $SYSDOCDIR/$DIR/device-mapper_info.txt
        eval $cmd                              >>  $SYSDOCDIR/$DIR/$D.txt 2>&1
     else
        echo " not available...skipping!" | tee -a $SYSDOCDIR/$DIR/device-mapper_info.txt
     fi   
 done
 echo "---device-mapper--------done!"
} 

function get_init.d() {
 echo "---init.d-------------------:"
 DIR=etc/init.d
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 cp  -a /$DIR/* $SYSDOCDIR/$DIR &> /dev/null
 ls -lR /$DIR/* >> $SYSDOCDIR/doc/init.d_files.txt
 echo "---init.d---------------done!"
}

function get_etc() {
 echo "---etc----------------------:"
 DIR=etc
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 # get links and copy original
 # find /etc -type l -exec ls -l {} \; | cut -d ">" -f 2 | tr -d " "
 echo "...*conf*..." 
 tar cf - --exclude="gconf" $(find /$DIR -name "*conf*" -type f) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 tar cf - --exclude="gconf" $(find /$DIR -name "*conf*" -type l) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...*.cf..." 
 tar cf - $(find /$DIR -name "*.cf"   -type f) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 tar cf - $(find /$DIR -name "*.cf"   -type l) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...*tab..." 
 tar cf - $(find /$DIR -name "*tab"  -type f) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 tar cf - $(find /$DIR -name "*tab"  -type l) 2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...xinet*..."
 tar cf - $(find /$DIR -name "xinet*")         2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...*cron*..."
 tar cf - $(find /$DIR -name "*cron*")         2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...other files..."
 for conf  in "motd" "issue" "login.defs" "profile" "hosts*" "services*" "sysconfig" \
              "passwd" "group" "shadow" "udev" "auto.*" "HOSTNAME" "lvm" ; do
     echo "...$conf..." 
     cp -ar /$DIR/$conf  $SYSDOCDIR/$DIR &> /dev/null
 done 
 echo "...pam.d..." 
 tar cf - $(find /$DIR -name "pam*" -type d)  2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...SuSEconfig..." 
 tar cf - $(find /$DIR -name "SuSEconfig" -type d)  2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 echo "...security..." 
 tar cf - $(find /$DIR -name "security" -type d)  2> /dev/null | (cd $SYSDOCDIR;tar xf -) &> /dev/null 
 if [[ -d /var/FlexFrame ]] ; then
    echo "...FlexFrame..." 
    cp -a /$DIR/FlexFrame  $SYSDOCDIR/$DIR &> /dev/null
    DIR=var/FlexFrame/etc
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -a /$DIR/sysconfig $SYSDOCDIR/$DIR  &> /dev/null
    cp -p /$DIR/*         $SYSDOCDIR/$DIR  &> /dev/null
 fi   
 echo "---etc------------------done!"
} 

function get_syslog() {
 echo "---syslog-------------------:"
 DIR=var/log
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 # to be compatible w/ old syslog
 cp  -a /$DIR/messages $SYSDOCDIR/$DIR &> /dev/null
 cp  -a /$DIR/boot.*msg $SYSDOCDIR/$DIR &> /dev/null
 for i in $(ls /$DIR/log.* 2> /dev/null |egrep  -v "\..*\."); do
     cp  -a $i $SYSDOCDIR/$DIR &> /dev/null
 done
 logfs=$(find /etc -name "*syslog*conf*")
 echo $logfs >> $SYSDOCDIR/doc/syslog_conf_info.txt
 logf=$(ls -tr $logfs |tail -1)
 echo "$logf is latest conf!" >> $SYSDOCDIR/doc/syslog_conf_info.txt
 echo -n "...syslog" | tee -a $SYSDOCDIR/doc/syslog_conf_info.txt
 echo $logf | grep ng > /dev/null
 if [[ $? == 0 ]] ; then
    logs=$(grep file\(\" $logf |egrep -v '#|dev' | cut -d '"' -f 2 |sort -u)
    echo "-ng" | tee -a $SYSDOCDIR/doc/syslog_conf_info.txt
 else 
    logs=$(grep /var $logf |grep -v "#" | tr  "\t" " "| tr -s " "| cut -d " " -f 2 | \
           sed -e "s/-\//\//"| sort -u)
    echo "(-old)" | tee -a $SYSDOCDIR/doc/syslog_conf_info.txt
 fi
 for i in $logs ; do
     logdir=$(dirname $i)
     if [[ ! -d $SYSDOCDIR/$logdir ]] ; then
        mkdir -p $SYSDOCDIR/$logdir
     fi
     cp -av $i $SYSDOCDIR/$logdir >> $SYSDOCDIR/doc/syslog_conf_info.txt
 done     
 echo "---syslog---------------done!"
}

function get_sar() {
 echo "---sar----------------------:"
 DIR=var/log/sa
 if [[ -d /$DIR ]] ; then
    cd /$DIR
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    SDdo=$(grep sa1 /etc/cron.d/sysstat | tr -s " "| cut -d " " -f 7-)
    bash -c "$SDdo"
    SDdo=$(grep sa2 /etc/cron.d/sysstat | tr -s " "| cut -d " " -f 7-)
    bash -c "$SDdo"
    cp -av $(ls sar* -tr |tail -3)             $SYSDOCDIR/$DIR >> $SYSDOCDIR/doc/sar_info.txt
    cp -av $(ls sa* -tr| grep -v sar |tail -3) $SYSDOCDIR/$DIR >> $SYSDOCDIR/doc/sar_info.txt
 else 
    echo "...sar (sysstat) not available...skipping!" | tee -a $SYSDOCDIR/doc/sar_info.txt   
 fi
 echo "---sar------------------done!"
}

function get_profile.d() {
 echo "---profile.d----------------:"
 DIR=etc/profile.d
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 cp  -a /$DIR/* $SYSDOCDIR/$DIR &> /dev/null
 echo "---profile.d------------done!"
}


function get_homedoc() {
 echo "---homedoc------------------:"
 DIR=root/doc     
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 if [[ -e /$DIR ]] ; then
    cp  -a /$DIR/* $SYSDOCDIR/$DIR &> /dev/null
 else
    echo "...~/doc not found...skipping!" | tee -a $SYSDOCDIR/doc/root_doc_info.txt
 fi
 echo "---homedoc--------------done!"
}

function get_network() {
 echo "---network------------------:"
 DIR=doc/network
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 for cmd  in "ifconfig" "netstat -r" "netstat -rn" "netstat -in" "netstat -n" "netstat -nl" \
             "ip addr" "ip route" "ip link" "iptables -L"; do
     D=$(echo $cmd |tr " " "_"| tr "/" "%");
     echo "...$cmd..." |  tee -a $SYSDOCDIR/$DIR/network_info.txt
     $cmd                 >> $SYSDOCDIR/$DIR/$D.txt
 done 
 which ethtool &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...ethtool..." | tee -a $SYSDOCDIR/$DIR/network_info.txt
    for eth in $(ip a | grep "<" | cut -d ":" -f 2 | tr -d " "); do 
        echo "---$eth:"  >> $SYSDOCDIR/$DIR/ethtool.txt
        ethtool $eth     >> $SYSDOCDIR/$DIR/ethtool.txt
        ethtool -i $eth  >> $SYSDOCDIR/$DIR/ethtool.txt 2>&1
    done   
 else
    echo "...ethtool not available...skipping!" | tee -a $SYSDOCDIR/$DIR/network_info.txt
 fi 
 echo "---network--------------done!"
}

function get_pci() {
 echo "---pci----------------------:"
 DIR=doc/hw
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 for cmd  in "lspci" "lspci -n" "lspci -tv" "lspci -vvv"  \
             ; do
     echo -n "...$cmd"                    | tee -a $SYSDOCDIR/$DIR/hw_info.txt
     which $(echo $cmd | cut -d " " -f 1) &>/dev/null
     if [[ $? == 0 ]]; then
        D=$(echo $cmd |tr " " "_"| tr "/" "%");
        echo "..."                        | tee -a $SYSDOCDIR/$DIR/hw_info.txt
        eval $cmd                              >>  $SYSDOCDIR/$DIR/$D.txt 2>&1
     else
        echo " not available...skipping!" | tee -a $SYSDOCDIR/$DIR/hw_info.txt
     fi   
 done
 echo "---pci------------------done!"
}

function get_powerpath() {
 echo "---powerpath----------------:"
 DIR=doc/EMC
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 which powermt &> /dev/null
 if [[ $? == 0 ]] ; then
    echo "...powermt release..." | tee -a $SYSDOCDIR/$DIR/powerpath_info.txt
    powermt release  >> $SYSDOCDIR/$DIR/powerpath_info.txt
    echo "...powermt display dev=all..." | tee -a $SYSDOCDIR/$DIR/powerpath_info.txt
    powermt display dev=all  >> $SYSDOCDIR/$DIR/powerpath_info.txt
    echo "...powermt display paths..." | tee -a $SYSDOCDIR/$DIR/powerpath_info.txt
    powermt display paths  >> $SYSDOCDIR/$DIR/powerpath_info.txt
    echo "...powermt check_registration..." | tee -a $SYSDOCDIR/$DIR/powerpath_info.txt
    powermt check_registration  >> $SYSDOCDIR/$DIR/powerpath_info.txt
 else
    echo "...powerpath not available...skipping!" | tee -a $SYSDOCDIR/$DIR/powerpath_info.txt
 fi 
 echo "---powerpath------------done!"
}

function get_system-status() {
 echo "---system-status------------:"
 DIR=doc/system-status
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 for cmd  in "cat /etc/SuSE-release" "SPident -vvvvv" "cat /etc/issue" "date" "uname -a" "top -bn 1" "du /sys" \
             "lsof" "chkconfig -l" "ps -ef" "sysctl -a" "bash -c 'ulimit -a'" "who" "last" \
             "nfsstat" "showmount -a" "mpstat -P ALL" "iostat -p ALL" "ntpq -p" "vmstat -a" "vmstat -m" \
             "vmstat -s" "free" "swapon -s" "runlevel" "pstree -a -c -l -n -p -A" "hostname"; do
     echo -n "...$cmd" | tee -a $SYSDOCDIR/$DIR/system-status_info.txt
     which $(echo $cmd | cut -d " " -f 1) &>/dev/null
     if [[ $? == 0 ]]; then
        D=$(echo $cmd |tr " " "_"| tr "/" "%");
        echo "..."     | tee -a $SYSDOCDIR/$DIR/system-status_info.txt
        eval $cmd      >>  $SYSDOCDIR/$DIR/$D.txt 2>&1
     else
        echo " not available...skipping!" | tee -a $SYSDOCDIR/$DIR/system-status_info.txt
     fi   
 done
 echo "---system-status--------done!"
}

function get_hw() {
 echo "---hw-----------------------:"
 DIR=doc/hw
 echo "...devices"                        | tee -a $SYSDOCDIR/$DIR/hw_info.txt
 for cmd  in "lshal" "lsscsi" "/opt/QLogic_Corporation/SANsurferCLI/scli -z all" "dmidecode"  \
             "sg_map -i -x" ; do
     echo -n "...$cmd"                    | tee -a $SYSDOCDIR/$DIR/hw_info.txt
     which $(echo $cmd | cut -d " " -f 1) &>/dev/null
     if [[ $? == 0 ]]; then
        D=$(echo $cmd |tr " " "_"| tr "/" "%");
        echo "..."                        | tee -a $SYSDOCDIR/$DIR/hw_info.txt
        eval $cmd                              >>  $SYSDOCDIR/$DIR/$D.txt 2>&1
     else
        echo " not available...skipping!" | tee -a $SYSDOCDIR/$DIR/hw_info.txt
     fi   
 done
 echo -n "...hwinfo"                      | tee -a $SYSDOCDIR/$DIR/hw_info.txt
 which hwinfo  &>/dev/null
 if [[ $? == 0 ]]; then
    echo ""
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    for cmd  in bios block bridge cdrom cpu disk floppy framebuffer gfxcard hub ide isapnp \
                keyboard memory monitor mouse netcard network partition pci scsi smp \
                storage-ctrl sys tape usb usb-ctrl vbe wlan zip; do
       echo "...--$cmd"                   | tee -a $SYSDOCDIR/$DIR/hw_info.txt
       hwinfo --$cmd   2>&1            | cat - >>  $SYSDOCDIR/$DIR/$cmd.txt
    done
 else
    echo " not available...skipping!"     | tee -a $SYSDOCDIR/$DIR/hw_info.txt
 fi  
 echo "---hw-------------------done:"
}

function get_BF-cblade() {
 echo "---BF-cblade----------------:"
 DIR=doc/BladeFrame_cblade
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 if (esh extnet &>/dev/null) ; then
    BFNAME="$(esh extnet | head -1 | cut -d " " -f 2)" 
    for cmd  in "esh bframe" "esh bframe -l" "esh extnet" "esh blade" "esh blade -l" \
                "/opt/egenera/bin/showme" "/opt/egenera/bin/showme -l" \
                "/opt/egenera/bin/pathtop -b -c 3" "/opt/egenera/bin/pathstat -c 3 -TS" \
                "/opt/egenera/bin/pathstat -c 3" "/opt/egenera/bin/perfstat -c 3" "esh san -A" \
                "esh san -A -l" "esh panmgr" "esh intnet" "esh pan" "esh pan -l" "esh pim" \
                "esh pserver" "esh pserver -l" "esh disk" "esh disk -l" "esh pool" \
                "esh pool -l" "egenera props" "esh eth" "esh eth -l" "esh lpan" "esh lpan -l" \
                "esh mon" "esh mon -l" "esh reth" "esh reth -l" "esh role" "esh role -l" \
                "esh rstat" "esh rstat -l" "esh sw" "esh sw -l" "esh user" "esh user -l" \
                "esh version $BFNAME/c1" "esh version $BFNAME/c2" ; do
       D=$(echo $cmd |tr " " "_"| tr "/" "%");
       echo "...$cmd..." 
       $cmd                                                    &> $SYSDOCDIR/$DIR/$D.txt
    done
    for cmd in "snmp" "snmpmgr" ; do 
        echo "...$cmd..."                                | tee -a $SYSDOCDIR/$DIR/snmp.txt
        esh $cmd -G                                            >> $SYSDOCDIR/$DIR/snmp.txt 2>&1
        for i in $(esh lpan | grep LPAN | cut -d " " -f 2) ; do 
            esh $cmd -L $i                                     >> $SYSDOCDIR/$DIR/snmp.txt 2>&1
        done
    done
    echo "...save_state (may last some min's)..."
    if [ -d /proc/egenera/ConfigFiles/ifcb ]
    then
        BFNAME=${BFNAME}-c1
    else
        BFNAME=${BFNAME}-c2
    fi
    /opt/egenera/bin/save_state --noExpired $SYSDOCDIR/$DIR/save-state_${BFNAME}_${TIMESTAMP}.tgz &> $SYSDOCDIR/$DIR/cblade_info.txt 
    echo ".../opt/egenera/install..."
    sDIR=opt/egenera/install
    mkdir -p $SYSDOCDIR/$sDIR  &> /dev/null
    cp -av /$sDIR/*  $SYSDOCDIR/$sDIR                   &> $SYSDOCDIR/$DIR/cblade_info.txt
 else
    echo "...this is not a BF-cBlade...skipping!" | tee -a $SYSDOCDIR/$DIR/cblade_info.txt
 fi   
 echo "---BF-cblade------------done!"
}

function get_snmp() {
 echo "---snmp---------------------:"
 DIR=doc/snmp
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 if [[ $SYSTYPE = "2.6" ]]; then
    dowalk="snmpwalk -On -Cp localhost -v 1 -c "
 else
    dowalk="snmpwalk -On -Cp localhost  "
 fi
 snmpconf="/$(ls -ltr $(find /etc -name "*snmpd.conf")| tail -1 | tr -s " " | cut -d "/" -f 2-)"    # the latest edited or none 
 snmpconf=$(echo $snmpconf | grep snmp)                       # check for any snmp-conf (otherwise content is only "ls -ltr .")
 ps -ef |grep snmpd | grep -v grep > /dev/null
 if [[ $? == 0 ]]; then 
    if [[ "$snmpconf" != "" ]]; then
       Community=$(grep com2sec $snmpconf | grep -v "#" | head -n 1 | tr "[:space:]" " " | tr -s " " | cut -d " " -f 4)
       if [[ "$Community" = "" ]]; then
          Community=$(grep community $snmpconf | grep -v "#" | head -n 1 | tr "[:space:]" " " | tr -s " " | cut -d " " -f 2)
       fi
       if [[ "$Community" = "" ]]; then
          echo "...could not determine community...trying 'public'!" | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
          Community="public"
          snmpconf="last resort"
       else
          echo "Community = $Community (from $snmpconf)"                   >> $SYSDOCDIR/$DIR/snmp_info.txt
       fi
       echo "...retrieving MIBII..."                                 | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
       $dowalk $Community .1                                                > $SYSDOCDIR/$DIR/snmp.MIBII.txt 2>> $SYSDOCDIR/$DIR/snmp_info.txt
       if [[ -e /etc/srvmagt ]]; then
          echo "...retrieving ServerView-MIB..."                     | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
          i=1
          while [[ $i -le 5 && $i -ne 0 ]] ; do
             echo -n "... $i"                                        | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
             sleep $(expr $i \* 2)
             $dowalk $Community -Cc enterprises.231.2.10                    > $SYSDOCDIR/$DIR/snmp.ServerView.txt 2>> $SYSDOCDIR/$DIR/snmp_info.txt
             res=$?
             if [[ $res != 0 ]]; then
                echo -n " :-( "                                      | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
                i=$(expr $i + 1)
             else
                echo -n " :-)"                                       | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
                i=0
             fi
          done
          echo "."
          if [[ -e /etc/srvmagt/AssetCli ]]; then
             echo "...retrieving ServerView-infos (may last some min's)..."  | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
             SVcommunity=$(grep community /etc/srvmagt/AssetCli/SVlist_system_data.ini | tr -d "\r" | cut -d "=" -f 2)
             if [[ "$Community" != "$SVcommunity" ]]; then
                echo "... !!! COMMUNITY not set properly in /etc/srvmagt/AssetCli/SVlist_system_data.ini !!!" \
                                                                     | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
                echo "... !!! (building temporaly proper environment)                                    !!!" \
                                                                     | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
                cp -a /etc/srvmagt $SYSDOCDIR
                ln -s $SYSDOCDIR/srvmagt /tmp/srvmagt   # must be /tmp (similar to /etc) for patching
                cd $SYSDOCDIR/srvmagt/AssetCli
		cat > SVlist_system_data.ini <<-EOF
			[All]
			community=$Community
			retries=1
			timeout=1
		EOF
                if [[ -e /usr/sbin/patchstr ]] ; then
                   SUBSTR="/usr/sbin/patchstr"
                else 
                   SUBSTR="$STARTDIR/patchstr"
                fi   
                $SUBSTR /etc/srvmagt/AssetCli/SVlist_system_data /etc /tmp > SVlist_system_data
                chmod 700 SVlist_system_data
                # sed -e "s/public/$Community/" /etc/srvmagt/AssetCli/SVlist_system_data.ini > SVlist_system_data.ini
                # ./SVlist_system_data >>  $SYSDOCDIR/$DIR/SVlist.txt
             else 
                cd /etc/srvmagt/AssetCli
             fi
             ./SVlist_system_data                                          >> $SYSDOCDIR/$DIR/SVlist.txt
             cd $SYSDOCDIR
             rm -r $SYSDOCDIR/srvmagt /tmp/srvmagt 2>/dev/null
          else
             echo "...ServerView-SVlist not available...skipping!"              | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
          fi
          amCLIpath=""
          for SV_RP in "/opt/fsc/RAID/bin" "/opt/fujitsu/ServerViewSuite/RAIDManager/bin" ; do
              if [[ -e "$SV_RP" ]] ; then 
                 amCLIpath="$SV_RP"
              fi
          done
          if [[ "$amCLIpath" != "" ]]; then
             echo "...retrieving ServerView-RAID infos..."           | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
             (export LD_LIBRARY_PATH=$amCLIpath;$amCLIpath/amCLI -l struct) > $SYSDOCDIR/$DIR/SV-RAID_amCLI-l_struct.txt
             (export LD_LIBRARY_PATH=$amCLIpath;$amCLIpath/amCLI -l all   ) > $SYSDOCDIR/$DIR/SV_RAID_amCLI-l_all.txt
          else
             echo "...ServerView-RAID not available...skipping!"     | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
          fi
          echo "...ServerView-srvmagt..."                            | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
          srvmagt                                                          >> $SYSDOCDIR/$DIR/snmp_info.txt 2>> $SYSDOCDIR/$DIR/snmp_info.txt
       else
          echo "...ServerView not available...skipping!"             | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
       fi
    else
       echo "...no snmp-config found...skipping!"                    | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
    fi
 else
    echo "...snmpd not running...skipping!"                          | tee -a $SYSDOCDIR/$DIR/snmp_info.txt
 fi
 echo "---snmp-----------------done!"
}

function get_packages() {
 echo "---packages-----------------:"
 DIR=doc/packages
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 echo "Package name                ;Version      ;Release  ;Install date-time        ;Size(byte);License    ;Description (short)     "  > $SYSDOCDIR/$DIR/rpm_packages.txt
 echo "----------------------------;-------------;---------;-------------------------;----------;-----------;------------------------" >> $SYSDOCDIR/$DIR/rpm_packages.txt
 rpm -qa --qf "%-28{NAME};%-13{VERSION};%-9{RELEASE};%-25{INSTALLTIME:date};%10{SIZE} ;%-10{LICENSE};%{SUMMARY}\n"\
              |sort                                                  >> $SYSDOCDIR/$DIR/rpm_packages.txt
 if [[ $? != 0 ]] ; then
    echo "...rpm query failed. Not a RPM-system???"            | tee -a $SYSDOCDIR/$DIR/rpm_packages.txt
 fi
 echo "...install repositories:"                               | tee -a $SYSDOCDIR/$DIR/repositories_info.txt
 for i in "zypper -v lr" "zypper sl -d" "rug ca"; do
     ir_prog=$(echo $i | cut -d " " -f 1)
     which $ir_prog &> /dev/null
     if [[ $? == 0 ]] ; then
        echo "...--$i..."                                        | tee -a $SYSDOCDIR/$DIR/repositories_info.txt
        ($i)                                                         >> $SYSDOCDIR/$DIR/repositories_info.txt 2>&1
     fi
 done
 echo "---packages-------------done!"
}

function get_XEN() {
 echo "---XEN----------------------:"
 DIR=doc/xen
 mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
 if [[ -d /proc/xen ]]; then
    for cmd  in "xm info" "xm vcpu-list" "xm info" "xm list" "xm list -l" "xm dmesg" "xm log" \
    ; do
       D=$(echo $cmd |tr " " "_"| tr "/" "%");
       echo "...$cmd..." 
       $cmd                          >> $SYSDOCDIR/$DIR/$D.txt
    done 
    DIR=etc/xen/vm
    mkdir -p $SYSDOCDIR/$DIR  &> /dev/null
    cp -av /$DIR/*  $SYSDOCDIR/$DIR &> $SYSDOCDIR/$DIR/xen_info.txt
 else
    echo "...this is not a XEN dom0...skipping!" | tee -a $SYSDOCDIR/$DIR/xen_info.txt
 fi  
 echo "---XEN------------------done:"
}

function resolve_link() {    # given as PAR1
 WD=$(pwd)                                                #working dir at start
 FD=$(dirname $1)                                         #filename dir-part
 FN=$(basename $1)                                        #filename name-part
 FL=$(ls -dl $1| cut -d "/" -f 2- | cut -d " " -f 3)      #file links to
 LD=$(dirname $FL)                                        #link dir-part (maybe abs or rel)
 LN=$(basename $FL)                                       #link name (filename)
 L1=$(echo $FL | cut -b 1)                                #1st char of link (if = / -> abs)
 if [[ "$L1" == "/" ]] ; then
    LT="Abs"                                              #link type (abs or rel)
    TD=${LD#/}                                            #org (w/out /) target dir
 else
    LT="Rel"
    PP=${WD#$SYSDOCDIR}                                   #pre path (SD + PP = WD)
    TD=${PP#/}/$FD/$LD
 fi
 if (file /$TD/$LN | grep -v " link" &>/dev/null) ; then
    if [[ ! -e $SYSDOCDIR/$TD/$LN ]] ; then
       echo  "...copying target of: /$TD/$LN"
       mkdir -p $SYSDOCDIR/$TD &>/dev/null
       cp -a /$TD/$LN $SYSDOCDIR/$TD/$LN &>/dev/null
    fi
 else
    echo "...not copying /$TD/$LN because of target-type=LINK"
 fi
}

##############################################################################
#
# do the core stuff
#
function core() {
 if [[ -e $SYSDOCDIR ]] ; then
    echo "$SYSDOCDIR already exists!  please rename it and start again..."
    exit 11 
 else
    mkdir $SYSDOCDIR
 fi
#
# 1st step: call SITAR (save old ones before)
# 
 run_sitar
#
# 2nd step: collect other files (incl. dir structure)
#
 mkdir -p $SYSDOCDIR/doc  &> /dev/null

 for i in $SYSDSETS ; do
     echo $SYSDX | grep $i &> /dev/null 
     if [ $? == 0 ] ; then
        echo -e "---$i------------------------ \t skipped due to exclusion by \"-x\"! "
     else
        get_$i
     fi
 done
#
# resolve links
#
for SUBDIR in etc sys var ; do
    echo  "resolving links in sysdoc/$SUBDIR..."
    cd $SYSDOCDIR/$SUBDIR
    for LINK in $(find . -type l) ; do
        resolve_link $LINK
    done
done
#
# pack README and filelist to sysdocdir
#
 echo  -n "copying README..."
 cp /usr/share/doc/packages/sysdoc/README $SYSDOCDIR &> /dev/null  # one of these both 
 cp $STARTDIR/README* $SYSDOCDIR                     &> /dev/null  # will fit ;-)
 echo "done"
 cd $(dirname $SYSDOCDIR)
 DIR=$(basename $SYSDOCDIR)
 echo  -n "creating file list..."
 find $DIR >> $SYSDOCDIR/file_list.txt
 echo "done"
}
#
# End of core
#
###############################################################################

function wrap() {
 echo "starting...($RUNSTART - (arguments: \"$SYSDA\")" 
 echo ""
 echo "Version: $VERSION..."   
 if [ $SYSDC == "1" ] ; then
    echo "---cleaning up /tmp first (required by parameter \"-c\")..." 
    for d in $(ls -1d /tmp/sysdoc* /tmp/srvmagt 2> /dev/null | grep -v $LOGFILE) ; do
        echo "...deleting: ${d}..."
        rm -r $d
    done
    echo "---cleanup--------------done:"
 fi
 time core 2>&1 
 echo ""
 echo "gathering finished (running from $RUNSTART to $(date +'%H:%M:%S'))"
}

###############################################################################
#
# main: start core via wrap (w/ logging)
#
#
RUNSTART=$(date +'%H:%M:%S')
SYSDC="0"
SYSDX=""

SYSDSETS=" proc sysfs lvm filesystems nfs primecluster boot ddm device-mapper init.d etc \
           syslog sar profile.d homedoc network pci powerpath system-status hw BF-cblade \
           postfix yast2logs snmp packages XEN "
export SYSDSETS=$(echo $SYSDSETS | tr -s " ")
export SYSDA="$*"

while [ "$1" != "" ] ; do 
   case "$1" in
    -V)  echo $VERSION
         exit 0
         ;;
    -c)  export SYSDC="1"
         shift
         ;;
    -x)  export SYSDX=$(echo $2 | tr "," " ")
         shift 2
         for i in $SYSDX ; do
            echo "_${SYSDSETS}_" | tr " " "_" | grep "_${i}_" &> /dev/null 
            if [ $? != 0 ] ; then
               echo ""
               echo "sysdoc: unknown (info)set \"$i\" aborting..."
               echo ""
               echo "valid sets are:"
               echo "$SYSDSETS" 
               echo ""
               exit 10
            fi
         done
         ;;
    *)   usage
         exit 10
         ;;
   esac
done
#
# go !!!
#
wrap 2>&1 | tee -a $LOGFILE
#
# pack and clean up
#
DIR=$(basename $SYSDOCDIR)
cd  $(dirname  $SYSDOCDIR)
echo -n "copying logfile ..."
mv  $LOGFILE $SYSDOCDIR &> /dev/null
echo "done"
echo -n "creating archive \" $SYSDOCDIR.tgz \"..."
tar czf $DIR.tgz  $DIR &> /dev/null
echo "done"
echo -n "cleaning up...."
rm -r $DIR
echo "done"
echo "sysdoc'ing is done!!!"

exit
