bond_interface.sh (835B)
1 #!/usr/bin/env bash 2 3 bond_device="bond0" 4 ethernet="ethernet" 5 wifi="wi-fi" 6 bond_option="@bond" 7 ethernet_option="@ethernet" 8 wifi_option="@wifi" 9 10 get_tmux_option() { 11 local -r option="$1" 12 local -r default_option="$2" 13 local -r option_value="$(tmux show-option -gqv "$option")" 14 if [ -z "$option_value" ] ; then 15 echo "$default_option" 16 else 17 echo "$option_value" 18 fi 19 } 20 21 network_device() { 22 local -r bond_device="$(get_tmux_option "$bond_option" "$bond_device")" 23 local current_device="$(awk '/Currently Active/ {print $NF}' /proc/net/bonding/${bond_device})" 24 if [[ $current_device =~ ^e ]] ; then 25 current_device="$(get_tmux_option "$ethernet_option" "$ethernet")" 26 elif [[ $current_device =~ ^w ]] ; then 27 current_device="$(get_tmux_option "$wifi_option" "$wifi")" 28 fi 29 30 echo "$current_device" 31 } 32 33 main() { 34 network_device 35 } 36 37 main