| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/bin/bash
- # info: list system interfaces
- # options: [format]
- #
- # The function for obtaining the list of network interfaces.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- format=${1-shell}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_FUNC/shared.func
- # Json function
- json_list_iface() {
- interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
- int_counter=$(echo "$interfaces" | wc -l)
- i=1
- echo '['
- # Listing ifaces
- for interface in $interfaces; do
- if [ "$i" -lt "$int_counter" ]; then
- echo -e "\t\"$interface\","
- else
- echo -e "\t\"$interface\""
- fi
- (( ++i))
- done
- echo "]"
- }
- # Shell function
- shell_list_iface() {
- interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
- if [ -z "$nohead" ]; then
- echo "INTERFACES"
- echo "----------"
- fi
- for interface in $interfaces; do
- echo "$interface"
- done
- }
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Listing domains
- case $format in
- json) json_list_iface ;;
- plain) nohead=1; shell_list_iface ;;
- shell) shell_list_iface ;;
- *) check_args '1' '0' '[format]' ;;
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|