v_list_sys_interfaces 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # info: list system interfaces
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of network interfaces.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared.func
  14. # Json function
  15. json_list_iface() {
  16. interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
  17. int_counter=$(echo "$interfaces" | wc -l)
  18. i=1
  19. echo '['
  20. # Listing ifaces
  21. for interface in $interfaces; do
  22. if [ "$i" -lt "$int_counter" ]; then
  23. echo -e "\t\"$interface\","
  24. else
  25. echo -e "\t\"$interface\""
  26. fi
  27. (( ++i))
  28. done
  29. echo "]"
  30. }
  31. # Shell function
  32. shell_list_iface() {
  33. interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
  34. if [ -z "$nohead" ]; then
  35. echo "INTERFACES"
  36. echo "----------"
  37. fi
  38. for interface in $interfaces; do
  39. echo "$interface"
  40. done
  41. }
  42. #----------------------------------------------------------#
  43. # Action #
  44. #----------------------------------------------------------#
  45. # Listing domains
  46. case $format in
  47. json) json_list_iface ;;
  48. plain) nohead=1; shell_list_iface ;;
  49. shell) shell_list_iface ;;
  50. *) check_args '1' '0' '[format]' ;;
  51. esac
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. exit