我很遗憾地发现我的脚本对我的基本理解有点过于复杂。我目前添加了功能和菜单来运行这些功能,但我不知道如何添加属性来运行所有功能。我很抱歉,如果我缺乏描述,但id就像在我的菜单中添加run all属性而不会真正破坏当前菜单方案的功能。提前谢谢
#!/bin/bash
# Linux host info script
# Matthew Morcaldi 2015
# DONUTS version 0.2.0 last update (2/24/2015)
# w00t be in r00t
# Config ------------------------------------------------
outfile="linux_info.txt"
#--------------------------------------------------------
#### uncomment (set -x) for debug
# set -x
outfile="linux_info.txt"
checkroot() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
}
header() {
echo '' | tee -a $outfile
echo '----------------------' | tee -a $outfile
echo "[*] $title" | tee -a $outfile
echo '----------------------' | tee -a $outfile
}
display_os() {
title="Display_OS"
header $title
/bin/uname -r | tee -a $outfile
dmidecode -t 1 | grep -i 'serial' | sed 's/^ *//' | tee -a $outfile
cat /etc/*-release | tee -a $outfile
dmidecode -t system -q | egrep -i 'Manufacturer: |Product|UUID' | \
sed 's/^ *//' | tee -a $outfile
/usr/bin/ipmitool bmc info | egrep -i 'Firmware revision' | tee -a $outfile
dmidecode -t bios -q | egrep -i 'version|vendor' | \
sed 's/^ *//' | tee -a $outfile
}
display_mount() {
title="Mount"
header $title
mount |column -t | tee -a $outfile
}
display_network_oob() {
title="Drac-Info"
header $title
ipmitool lan print | egrep -i 'IP Address|MAC Address|Default Gateway IP|Subnet Mask' | tee -a $outfile
}
display_networking() {
title="Networking"
header $title
ifconfig -a | tee -a $outfile
arp -e | tee -a $outfile
}
display_bonding() {
if [ -f /proc/net/bonding/bond0 -a -f /bin/netstat ] ; then
title="Bonding"
header $title
cat /proc/net/bonding/bond0 | sed 's/^ *//' | tee -a $outfile
/bin/netstat -ni | column -t | tee -a $outfile
else
echo "Bond0 or netstat does not exist skipping"
fi
}
display_switch_info() {
if [ -f /usr/sbin/lldpctl ] ; then
title="Switch-Port-Information"
header $title
lldpctl | egrep '(Interface|VLAN|PortDescr|SysName|ChassisID)' | \
sed 's/^ *//' | tee -a $outfile
else
echo "Switch file LLDPCTL does not exist skipping"
fi
}
display_CPU_info() {
title="CPU-Info"
header $title
cat /proc/cpuinfo | egrep -i 'processor|vendor_id|model name|cpu MHz|physical id|siblings|core id|cpu cores' | \
sed 's/^ *//' | tee -a $outfile
/usr/bin/lscpu | egrep -i 'Architecture|CPU op-mode|Hyper|virtualization|CPU ' | \
sed 's/^ *//' | tee -a $outfile
}
show_disks_dell() {
if [ -f /opt/MegaRAID/MegaCli/MegaCli64 ] ; then
title="Dell-Raid"
header $title
/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll | \
egrep -i 'count|^Device Id: |firmware state' | \
grep -v 'Count: 0' | \
perl -p -e 's/Firmware state: (.*)$/Firmware state: $1\n/' | tee -a $outfile
/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL | \
egrep -i 'virtual|cache|state|raid level|name|size|number' | tee -a $outfile
else
echo "skipping Dell disk check"
fi
}
show_battery_dell() {
if [ -f /opt/MegaRAID/MegaCli/MegaCli64 ]; then
title="Dell-Battery"
header $title
/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -a0 | \
egrep -i 'isSOHGood|Charger Status|Capacity|Relative|Charging' | \
sed 's/^ *//' | tee -a $outfile
else
echo "skipping Dell battery check"
fi
}
show_disks_hp() {
if [ -f /usr/sbin/hpacucli ]; then
title="HP-Raid"
header $title
hpacucli ctrl all show config detail | \
sed 's/^ *//' | tee -a $outfile
else
echo "skipping HP disk check"
fi
}
show_battery_hp() {
if [ -f /usr/sbin/hpacucli ]; then
title="HP-Battery"
header $title
hpacucli ctrl all show status | \
sed 's/^ *//' | tee -a $outfile
else
echo "skipping HP battery check"
fi
}
show_sysprofile_dell() {
if [ -f /opt/dell/toolkit/bin/syscfg ]; then
title="BIOS power settings Dell"
header $title
/opt/dell/toolkit/bin/syscfg --SysProfile | tee -a $outfile
/opt/dell/toolkit/bin/syscfg --ProcPwrPerf | tee -a $outfile
/opt/dell/toolkit/bin/syscfg --logicproc | tee -a $outfile
/opt/dell/toolkit/bin/syscfg --virtualization | tee -a $outfile
else
echo "skipping Dell power settings check"
fi
}
show_sysprofile_HP() {
if [ -f /opt/hp/conrep ]; then
title="BIOS power settings HP"
header $title
cd /opt/hp/
./conrep -s -f output
cd
less /opt/hp/output | grep Hyperthreading | tee -a $outfile
less /opt/hp/output | grep CPU_Virtualization | tee -a $outfile
less /opt/hp/output | grep HP_Power_Profile | tee -a $outfile
rm -f /opt/hp/output
else
echo "skipping HP power settings check"
fi
}
display_dimms() {
title="Memory"
header $title
cat /proc/meminfo|grep MemTotal | tee -a $outfile
free -g | tee -a $outfile
dmidecode -t Memory Device -q |egrep -i 'Size:|Type: D|Locator: D' | \
perl -p -e 's/Type: (.*)$/Type: $1\n/' | tee -a $outfile
}
sel_list() {
title="SEL"
header $title
ipmitool sel elist | tee -a $outfile
}
exit_script() {
title="exit_script"
header $title
service ipmi stop
exit 0
}
##########
checkroot
echo 'Press [Enter] key to continue.'
read goforit
service ipmi start
while true
do
echo "Menu: "
FUNCTION_COUNT=15
STUFFTODOFUNC=("display_os" "display_mount" "display_CPU_info" "display_dimms" "sel_list" "show_sysprofile_dell" "show_sysprofile_HP" "show_disks_hp" "show_battery_hp" "show_disks_dell" "show_battery_dell" "display_network_oob" "display_networking" "display_bonding" "display_switch_info" "exit_script" )
STUFFTODONAME=('Display_OS' 'Display_Mount_Info' 'Display_CPU_Info' 'Display_Memory' 'System_Event_List' 'Dell_BIOS_Power_Settings' 'HP_BIOS_Power_Settings' 'HP_RAID' 'HP_RAID_Battery' 'Dell_RAID' 'Dell_RAID_Battery' 'Display_Network_OOB' 'Display_Network' 'display_bonding' 'Display_Switch_Port_Information' 'exit' )
COUNT=0
for ITEM in ${STUFFTODONAME[*]}
do
echo -n " ${COUNT}. ${ITEM} " | tr '_' ' '
COUNT=$(( $COUNT + 1 ))
done
echo ""
echo -n "Please Select From Above.:"
read FUNCTION
echo ${STUFFTODONAME[FUNCTION]}
echo ""
${STUFFTODOFUNC[FUNCTION]}
done