v_list_sys_interfaces 1.6 KB

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