This repository was archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathenicstat
More file actions
61 lines (55 loc) · 1.28 KB
/
enicstat
File metadata and controls
61 lines (55 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# enicstat - Get interface speed/duplex from ethtool; use with nicstat
#
# Copyright (c) 2009, Tim.Cook@sun.com
#
# nicstat is licensed under the Artistic License 2.0. You can find
# a copy of this license as LICENSE.txt included with the nicstat
# distribution, or at http://www.perlfoundation.org/artistic_license_2_0
PROG=${0##*/}
#-- Add /sbin to PATH, as that is where ethtool usually is
export PATH=${PATH}:/sbin
#-- Get list of interface names
while read a b c
do
case $a in
'Inter'* | 'face' ) ;;
*':'[0-9]* | *':' )
ifname=${a%:*}
interfaces="$interfaces $ifname"
;;
esac
done < /proc/net/dev
#-- Get speed/duplex of each interface using ethtool
nl='
'
for if in $interfaces
do
ifname=
speed=
duplex=
valid=false
settings=`ethtool "$if" 2>/dev/null`
x=${settings#Settings for }
ifname=${x%%:*}
x=${settings##* Speed: }
case $x in
[1-9]*'Mb/s'* )
valid=true ;;
esac
speed=${x%%Mb/s$nl*}
x=${settings##* Duplex: }
duplex=${x%%$nl*}
case $valid,$ifspeeds in
true, )
ifspeeds="${ifname}:$speed$duplex" ;;
true,* )
ifspeeds="$ifspeeds,${ifname}:$speed$duplex" ;;
esac
done
if [ -z "$ifspeeds" ]; then
echo "$PROG: warning: failed to obtain any interface speeds" >&2
exec nicstat "$@"
fi
#-- Run nicstat with what we got
exec nicstat -S "$ifspeeds" "$@"