#!/bin/sh

source fcns.shinc;  # dhs script functions library

echo "##*************************************##"
echo "Running Processes (ps)"
echo ""
ps
echo ""
echo "Running Processes (top)"
echo ""
top -n 1 -b
echo ""

echo "##*************************************##"
echo "Mounted File Systems (fs)"
echo ""
echo ""
df
echo ""
echo "Flash Memory Partitons (/proc/mtd)"
echo ""
cat /proc/mtd
echo ""
cat /proc/moose/mtd
echo ""
echo "Contents of root directory (/)"
ls -l /
echo ""

echo "##*************************************##"
echo "(SysInfo)"
echo ""
#SNMP Community Strings should not be displayed in logs.  Parse out.
cat /cfg/sysinfo/system.xml | grep -v "snmpWriteCommunity" | grep -v "snmpReadCommunity"
echo ""

echo "##*************************************##"
echo "Latest MC bundle information (versions.txt)"
echo ""
cat /cfg/version.txt
echo ""

echo "##*************************************##"
echo "(AppInfo)"
echo "Active App:"
get_active_app
echo ""
echo "/mnt/app1/mc_system_version.txt"
echo ""
test -f /mnt/app1/mc_system_version.txt && cat /mnt/app1/mc_system_version.txt
echo ""
echo "/mnt/app2/mc_system_version.txt"
echo ""
test -f /mnt/app2/mc_system_version.txt && cat /mnt/app2/mc_system_version.txt
echo ""

echo "##*************************************##"
echo "Contents of read/write flash file system (/cfg)"
ls -R /cfg
echo ""
echo ""
echo "Lg files are using space from the active processes (du /cfg/log)"
echo ""
du -k /cfg/log
echo ""
echo "Contents of /cfg/users"
echo ""
ls -l /cfg/users
echo ""

echo "##*************************************##"
echo "(Moose)"
echo ""
filelist=`find /proc/moose -print`
for file in $filelist
do
    if [ `basename $file` == 'ping' ]
    then
        continue
    fi

    if [ -f $file ]
    then
        echo "$file"
        cat $file
        echo ""
    fi
done

echo "##*************************************##"
echo "(Mac3h)"
echo ""
filelist=`find /proc/driver/mac3h/ -print`
for file in $filelist
do
    if [ `basename $file` == 'testme' ]
    then
        continue
    fi

    if [ -f $file ]
    then
        echo "$file"
        cat $file
        echo ""
    fi
done

echo "##*************************************##"
echo "Network Configuration (ifconfig)"
echo ""
ifconfig
echo ""

echo "##*************************************##"
echo "Network Status (netstat -pan)"
echo ""
netstat -pan
echo ""

echo "##*************************************##"
echo "(CPLD)"
echo "CPLD Type:"
cpldtype
echo ""
echo "CPLD Rev:"
cpldrev
echo ""

echo "##*************************************##"
echo "MC Info (mcinfo)"
echo "MC Serial Number:"
echo ""
getMacAddr serial; # returns val to this variable
echo $serial
echo ""
echo "Kernel Command Line:"
echo ""
genAllMtdPropVariables "$(cat /proc/moose/mtd)"
head -c 200 /dev/mtd$mtdnbr_mc_boot_meta | strings
echo ""
echo "Last Codeload:"
echo ""
if [ -f /cfg/codeload.last ]
then
    cat /cfg/codeload.last
else
    echo "NONE"
fi
echo ""
echo "Last PFU:"
echo ""
if [ -f /cfg/pfu.last ]
then
    cat /cfg/pfu.last
else
    echo "NONE"
fi
echo ""
echo "Last Getlogs:"
echo ""
if [ -f /cfg/getlogs.last ]
then
    cat /cfg/getlogs.last
else
    echo "NONE"
fi
echo ""

echo "##*************************************##"
echo "Last Codeload"
echo ""
if [ -f /cfg/codeload.last ]
then
    cat /cfg/codeload.last
else
    echo "NONE"
fi
echo ""

echo "##*************************************##"
echo "Last PFU"
echo ""
if [ -f /cfg/pfu.last ]
then
    cat /cfg/pfu.last
else
    echo "NONE"
fi
echo ""

echo "##*************************************##"
echo "Last Getlogs"
echo ""
if [ -f /cfg/getlogs.last ]
then
    cat /cfg/getlogs.last
else
    echo "NONE"
fi
echo ""

echo "##*************************************##"
echo "Mem Tracker logs"
echo ""
getmemtrack
echo ""

echo "##*************************************##"
echo "Sys Tracker logs"
echo ""
getsystrack
echo ""

echo "##*************************************##"
echo "VM Tracker logs"
echo ""
getvmtrack
echo ""

echo "##*************************************##"
echo "spawner logs"
echo ""
getspawner
echo ""

exit 0
