Posted By

mprabhuram on 07/15/09


Tagged

info unix network shellscript centos


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

scilec
mprabhuram
tazjel


Shell Script For Collecting Information on the Linux Network Configuration


 / Published in: Bash
 

URL: http://bash.cyberciti.biz/networking/shell-script-to-find-linux-network-configurations/

This shell script is tested under CentOS / RHEL and Fedora Linux. It should also work under other Linux distributions. If you would like to collect and submit information on your network configuration to your sr. Linux / UNIX admin use this script.

  1. #!/bin/bash
  2. # A Linux Shell script to collect information on your network configuration.
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # -------------------------------------------------------------------------
  10. # Last updated: Jun-03-2009
  11. # -------------------------------------------------------------------------
  12. HWINF=/usr/sbin/hwinfo
  13. IFCFG=/sbin/ifconfig
  14. IP4FW=/sbin/iptables
  15. IP6FW=/sbin/ip6tables
  16. LSPCI=/sbin/lspci
  17. ROUTE=/sbin/route
  18. NETSTAT=/bin/netstat
  19. LSB=/usr/bin/lsb_release
  20.  
  21. ## files ##
  22. DNSCLIENT="/etc/resolv.conf"
  23. DRVCONF="/etc/modprobe.conf"
  24. NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"
  25. NETCFC="/etc/sysconfig/network-scripts/ifcfg-eth?"
  26. NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?"
  27. SYSCTL="/etc/sysctl.conf"
  28.  
  29. ## Output file ##
  30. OUTPUT="network.$(date +'%d-%m-%y').info.txt"
  31.  
  32. ## Email info to?? ##
  33. SUPPORT_ID="[email protected]"
  34.  
  35. chk_root(){
  36. local meid=$(id -u)
  37. if [ $meid -ne 0 ];
  38. then
  39. echo "You must be root user to run this tool"
  40. exit 999
  41. fi
  42. }
  43.  
  44. write_header(){
  45. echo "---------------------------------------------------" >> $OUTPUT
  46. echo "$@" >> $OUTPUT
  47. echo "---------------------------------------------------" >> $OUTPUT
  48. }
  49.  
  50. dump_info(){
  51. echo "* Hostname: $(hostname)" >$OUTPUT
  52. echo "* Run date and time: $(date)" >>$OUTPUT
  53.  
  54. write_header "Linux Distro"
  55. echo "Linux kernel: $(uname -mrs)" >>$OUTPUT
  56. $LSB -a >> $OUTPUT
  57.  
  58. [ -x ${HWINF} ] && write_header "${HWINF} --network_ctrl"
  59. [ -x ${HWINF} ] && ${HWINF} --network_ctrl >> $OUTPUT
  60.  
  61. [ -x ${HWINF} ] && write_header "${HWINF} --isapnp"
  62. [ -x ${HWINF} ] && ${HWINF} --isapnp >> $OUTPUT
  63.  
  64. write_header "PCI Devices"
  65. ${LSPCI} -v >> $OUTPUT
  66.  
  67. write_header "$IFCFG Output"
  68. $IFCFG >> $OUTPUT
  69.  
  70. write_header "Kernel Routing Table"
  71. $ROUTE -n >> $OUTPUT
  72.  
  73. write_header "Network Card Drivers Configuration $DRVCONF"
  74. [ -f $DRVCONF ] && grep eth $DRVCONF >> $OUTPUT || echo "Error $DRVCONF file not found." >> $OUTPUT
  75.  
  76. write_header "DNS Client $DNSCLIENT Configuration"
  77. [ -f $DNSCLIENT ] && cat $DNSCLIENT >> $OUTPUT || echo "Error $DNSCLIENT file not found." >> $OUTPUT
  78.  
  79. write_header "Network Configuration File"
  80. for f in $NETCFC
  81. do
  82. if [ -f $f ]
  83. then
  84. echo "** $f **" >> $OUTPUT
  85. cat $f >> $OUTPUT
  86. else
  87. echo "Error $f not found." >> $OUTPUT
  88. fi
  89. done
  90.  
  91. write_header "Network Aliase File"
  92. for f in $NETALIASCFC
  93. do
  94. if [ -f $f ]
  95. then
  96. echo "** $f **" >> $OUTPUT
  97. cat $f >> $OUTPUT
  98. else
  99. echo "Error $f not found." >> $OUTPUT
  100. fi
  101. done
  102.  
  103. write_header "Network Static Routing Configuration"
  104. for f in $NETSTATICROUTECFC
  105. do
  106. if [ -f $f ]
  107. then
  108. echo "** $f **" >> $OUTPUT
  109. cat $f >> $OUTPUT
  110. else
  111. echo "Error $f not found." >> $OUTPUT
  112. fi
  113. done
  114.  
  115. write_header "IP4 Firewall Configuration"
  116. $IP4FW -L -n >> $OUTPUT
  117.  
  118. write_header "IP6 Firewall Configuration"
  119. $IP6FW -L -n >> $OUTPUT
  120.  
  121. write_header "Network Stats"
  122. $NETSTAT -s >> $OUTPUT
  123.  
  124. write_header "Network Tweaks via $SYSCTL"
  125. [ -f $SYSCTL ] && cat $SYSCTL >> $OUTPUT || echo "Error $SYSCTL not found." >>$OUTPUT
  126.  
  127. echo "The Network Configuration Info Written To $OUTPUT. Please email this file to $SUPPORT_ID."
  128. }
  129.  
  130. chk_root
  131. dump_info

Report this snippet  

You need to login to post a comment.