v_list_sys_interfaces 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/func/shared.sh
  13. # Json function
  14. json_list_iface() {
  15. interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
  16. int_counter=$(echo "$interfaces" | wc -l)
  17. i=1
  18. echo '['
  19. # Listing ifaces
  20. for interface in $interfaces; do
  21. if [ "$i" -lt "$int_counter" ]; then
  22. echo -e "\t\"$interface\","
  23. else
  24. echo -e "\t\"$interface\""
  25. fi
  26. (( ++i))
  27. done
  28. echo "]"
  29. }
  30. # Shell function
  31. shell_list_iface() {
  32. interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
  33. if [ -z "$nohead" ]; then
  34. echo "INTERFACES"
  35. echo "----------"
  36. fi
  37. for interface in $interfaces; do
  38. echo "$interface"
  39. done
  40. }
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Listing domains
  45. case $format in
  46. json) json_list_iface ;;
  47. plain) nohead=1; shell_list_iface ;;
  48. shell) shell_list_iface ;;
  49. *) check_args '1' '0' '[format]' ;;
  50. esac
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. exit