random bash scripts
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.

90 lines
2.7 KiB

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