Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added(utils): nic-model-list - show models of network cards. #216

Merged
merged 2 commits into from
Dec 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added(utils): nic-model-list - show models of network cards.
  • Loading branch information
strizhechenko committed Dec 24, 2018
commit 864114a41ed3d15652674b710d0a82f70831f453
50 changes: 50 additions & 0 deletions utils/nic-model-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -eu
# echo "$0 $@ [$$] START" >&2
declare DEVICE_REGEX="(eth|em|en|bond|p[0-9]*p)[0-9\.]+"

if [ "{1:-}" == '--help' ]; then
echo "Info: $0 показывает модели сетевых карт в системе"
echo "Usage: $0 без параметров"
echo "Example: $0"
exit 0
fi

rx_buf() {
ethtool -g "$1" 2>/dev/null | tac | grep "RX:" | egrep -o "[0-9]+" | tr '\n' '/'| sed 's|/$||g'
return 0
}

show_device() {
local eth="$1"
local id="$2"
is_vlan=0
if ethtool -i "$eth" | grep -q '802.1Q VLAN Support'; then
is_vlan=1
fi
if [ "$is_vlan" = 0 ]; then

echo "$eth: $(grep -w $id /tmp/lspci.tmp) rx: $(rx_buf "$eth")"
else
echo "$eth: VLAN interface"
fi
return 0
}

main() {
local eth
local id
for eth in $(egrep -o "$DEVICE_REGEX" /proc/net/dev | sort -u); do
for id in $(ethtool -i "$eth" | grep bus-info | sed 's/.*0000:https://'); do
show_device "$eth" "$id"
done
done
return 0
}

lspci > /tmp/lspci.tmp
main

# echo "$0 $@ [$$] SUCCESS"
exit 0