#! /bin/sh

#####################    example: ./nxdebug-one   ##############

	self_adp_test=0
	a=$( date | cut -d " " -f 2)
	b=$( date | cut -d " " -f 3)
	c=$( date | cut -d " " -f 4)
	d=$( date | cut -d " " -f 6)
	nxoutput=/tmp/nxoutput.$a-$b-$c-$d   #result file

   echo "#############################################################" > $nxoutput
   echo "=================== date and hostname========================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   date >> $nxoutput
   hostname >> $nxoutput
   echo "" >> $nxoutput
   echo "" >> $nxoutput

   echo "#############################################################" >> $nxoutput
   echo "=================== host os info ============================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== uname -a ================================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   uname -a >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /etc/issue ==========================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /etc/issue >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /boot/config-$(uname -r) ============" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /boot/config-$(uname -r) >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "=================== Module info =============================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== lsmod|grep qlcnic ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   lsmod|grep qlcnic >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== lsmod|grep netxen ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   lsmod|grep netxen >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== lsmod|grep nx_ ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   lsmod|grep nx_ >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== rpm -qa =================================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   rpm -qa  >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "===================== system info ===========================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/cpuinfo =======================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/cpuinfo >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/meminfo =======================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/meminfo >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /etc/grub.conf ======================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /etc/grub.conf >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "================= cat /etc/modprobe.conf ====================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /etc/modprobe.conf >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/interrupts ====================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/interrupts >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/slabinfo ======================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/slabinfo >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/buddyinfo =====================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/buddyinfo >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/iomem  ========================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/iomem >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/zoneinfo =======================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/zoneinfo >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /proc/net/dev_mcast =================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /proc/net/dev_mcast >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== sysctl -a ===============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   sysctl -a >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== lspci -vvv ==============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   lspci -vvv >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== netstat -S ==============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   netstat -S >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "======================== route ==============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   route >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "========================== arp ==============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   arp >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "=======================  Process details  ===================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "======================== ps aux =============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ps aux >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "========================   Log messages  ====================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "============================= dmesg =========================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   dmesg >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== cat /var/log/messages ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /var/log/messages >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "========================   ifconfig info  ===================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ifconfig ================================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ifconfig >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ifconfig -a =============================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ifconfig -a >> $nxoutput
   echo "" >> $nxoutput

   echo "" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "======================== Ethtool details ====================" >> $nxoutput
   echo "#############################################################" >> $nxoutput
   echo "" >> $nxoutput

dir=/opt/qlcnic
ls /sys/class/net/ > /tmp/listing

while read ifacename
do
   found=$( ethtool -i $ifacename | grep -e qlcnic -e netxen_nic -e nx_nic | wc -l)
   if [ $found == 0 ]; then continue; fi

   echo "=============================================================" >> $nxoutput
   echo "============ Network script for $ifacename  =================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   cat /etc/sysconfig/network-scripts/ifcfg-$ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool $ifacename  =====================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -i $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -i $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -S $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -S $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -a $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -a $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -g $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -g $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -c $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -c $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "=================== ethtool -k $ifacename ===================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -k $ifacename >> $nxoutput
   echo "" >> $nxoutput

   echo "=============================================================" >> $nxoutput
   echo "================ Register dump of $ifacename ================" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   $dir/parse_dump.sh $ifacename >> $nxoutput
   echo "" >> $nxoutput

done < /tmp/listing

self_adp_test=$1
while read ifacename
do
   found=$( ethtool -i $ifacename | grep -e qlcnic -e netxen_nic -e nx_nic | wc -l)
   if [ $found ==  0 ] || [ $self_adp_test == 0 ]; then continue; fi

   echo "=============================================================" >> $nxoutput
   echo "=============== Self-adapter test on $ifacename =============" >> $nxoutput
   echo "=============================================================" >> $nxoutput
   ethtool -t $ifacename >> $nxoutput
   echo "" >> $nxoutput

done < /tmp/listing

rm /tmp/listing

   echo "done" >> $nxoutput

        echo "done"
        echo

