You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7 KiB

  1. #!/bin/bash
  2. # script to collect network info and store in a timestamped txt file
  3. IP4FW=/sbin/iptables
  4. IP6FW=/sbin/ip6tables
  5. LSPCI=/usr/bin/lspci
  6. ROUTE=/sbin/route
  7. NETSTAT=/bin/netstat
  8. LSB=/usr/bin/lsb_release
  9. ## files ##
  10. DNSCLIENT="/etc/resolv.conf"
  11. DRVCONF="/etc/modprobe.conf"
  12. NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"
  13. NETCFC="/etc/sysconfig/network-scripts/ifcfg-eth?"
  14. NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?"
  15. SYSCTL="/etc/sysctl.conf"
  16. ## Output file ##
  17. OUTPUT="network.$(date +'%d-%m-%y').info.txt"
  18. ## Email info to?? ##
  19. SUPPORT_ID="your_name@service_provider.com"
  20. chk_root() {
  21. local meid=$(id -u)
  22. if [ $meid -ne 0 ]; then
  23. echo "You must be root user to run this tool"
  24. exit 999
  25. fi
  26. }
  27. write_header() {
  28. echo "---------------------------------------------------" >>$OUTPUT
  29. echo "$@" >>$OUTPUT
  30. echo "---------------------------------------------------" >>$OUTPUT
  31. }
  32. dump_info() {
  33. echo "* Hostname: $(hostname)" >$OUTPUT
  34. echo "* Run date and time: $(date)" >>$OUTPUT
  35. write_header "Linux Distro"
  36. echo "Linux kernel: $(uname -mrs)" >>$OUTPUT
  37. $LSB -a >>$OUTPUT
  38. [ -x ${HWINF} ] && write_header "${HWINF}"
  39. [ -x ${HWINF} ] && ${HWINF} >>$OUTPUT
  40. [ -x ${HWINF} ] && write_header "${HWINF}"
  41. [ -x ${HWINF} ] && ${HWINF} >>$OUTPUT
  42. write_header "PCI Devices"
  43. ${LSPCI} -v >>$OUTPUT
  44. write_header "$IFCFG Output"
  45. $IFCFG >>$OUTPUT
  46. write_header "Kernel Routing Table"
  47. $ROUTE -n >>$OUTPUT
  48. write_header "Network Card Drivers Configuration $DRVCONF"
  49. [ -f $DRVCONF ] && grep eth $DRVCONF >>$OUTPUT || echo "Error $DRVCONF file not found." >>$OUTPUT
  50. write_header "DNS Client $DNSCLIENT Configuration"
  51. [ -f $DNSCLIENT ] && cat $DNSCLIENT >>$OUTPUT || echo "Error $DNSCLIENT file not found." >>$OUTPUT
  52. write_header "Network Configuration File"
  53. for f in $NETCFC; do
  54. if [ -f $f ]; then
  55. echo "** $f **" >>$OUTPUT
  56. cat $f >>$OUTPUT
  57. else
  58. echo "Error $f not found." >>$OUTPUT
  59. fi
  60. done
  61. write_header "Network Aliase File"
  62. for f in $NETALIASCFC; do
  63. if [ -f $f ]; then
  64. echo "** $f **" >>$OUTPUT
  65. cat $f >>$OUTPUT
  66. else
  67. echo "Error $f not found." >>$OUTPUT
  68. fi
  69. done
  70. write_header "Network Static Routing Configuration"
  71. for f in $NETSTATICROUTECFC; do
  72. if [ -f $f ]; then
  73. echo "** $f **" >>$OUTPUT
  74. cat $f >>$OUTPUT
  75. else
  76. echo "Error $f not found." >>$OUTPUT
  77. fi
  78. done
  79. write_header "IP4 Firewall Configuration"
  80. $IP4FW -L -n >>$OUTPUT
  81. write_header "IP6 Firewall Configuration"
  82. $IP6FW -L -n >>$OUTPUT
  83. write_header "Network Stats"
  84. $NETSTAT -s >>$OUTPUT
  85. write_header "Network Tweaks via $SYSCTL"
  86. [ -f $SYSCTL ] && cat $SYSCTL >>$OUTPUT || echo "Error $SYSCTL not found." >>$OUTPUT
  87. echo "The Network Configuration Info Written To $OUTPUT. Please email this file to $SUPPORT_ID."
  88. }
  89. chk_root
  90. dump_info