File tree Expand file tree Collapse file tree 2 files changed +38
-17
lines changed
server/modules/shell_files Expand file tree Collapse file tree 2 files changed +38
-17
lines changed Original file line number Diff line number Diff line change 3
3
files=(/sys/class/net/* )
4
4
pos=$(( ${# files[*]} - 1 ))
5
5
last=${files[$pos]}
6
+ in1=()
6
7
7
8
json_output=" {"
8
9
9
- for interface in " ${files[@]} "
10
+ for interface in " ${files[@]} "
10
11
do
11
12
basename=$( basename " $interface " )
12
-
13
+
13
14
# find the number of bytes transfered for this interface
14
- in1=$( cat /sys/class/net/" $basename " /statistics/rx_bytes)
15
+ in1+=( $( cat /sys/class/net/" $basename " /statistics/rx_bytes) )
16
+ done
15
17
16
- # wait a second
17
- sleep 1
18
+ # wait a moment
19
+ sleep 0.5
18
20
21
+ for interface in " ${files[@]} "
22
+ do
23
+ basename=$( basename " $interface " )
19
24
# check same interface again
20
25
in2=$( cat /sys/class/net/" $basename " /statistics/rx_bytes)
21
26
27
+ # read and remove first element
28
+ in=${in1[0]}
29
+ unset in1[0]
30
+ in1=( " ${in1[@]} " )
31
+
22
32
# get the difference (transfer rate)
23
- in_bytes=$(( in2 - in 1 ))
33
+ in_bytes=$(( in2 - in ))
24
34
25
35
# convert transfer rate to KB
26
- in_kbytes=$(( in_bytes / 1024 ))
36
+ in_kbytes=$(( in_bytes / 1024 * 2 ))
27
37
28
38
# convert transfer rate to KB
29
39
json_output=" $json_output \" $basename \" : $in_kbytes "
33
43
then
34
44
# add a comma to the line (JSON formatting)
35
45
json_output=" $json_output ,"
36
- fi
46
+ fi
37
47
done
38
48
39
49
# close the JSON object & print to screen
Original file line number Diff line number Diff line change 3
3
files=(/sys/class/net/* )
4
4
pos=$(( ${# files[*]} - 1 ))
5
5
last=${files[$pos]}
6
+ out1=()
6
7
7
8
json_output=" {"
8
9
9
- for interface in " ${files[@]} "
10
+ for interface in " ${files[@]} "
10
11
do
11
12
basename=$( basename " $interface " )
12
-
13
+
13
14
# find the number of bytes transfered for this interface
14
- out1=$( cat /sys/class/net/" $basename " /statistics/tx_bytes)
15
+ out1+=( $( cat /sys/class/net/" $basename " /statistics/tx_bytes) )
16
+ done
17
+
18
+ # wait a moment
19
+ sleep 0.5
15
20
16
- # wait a second
17
- sleep 1
21
+ for interface in " ${files[@]} "
22
+ do
23
+ basename=$( basename " $interface " )
18
24
19
25
# check same interface again
20
- out2=$( cat /sys/class/net/" $basename " /statistics/tx_bytes)
26
+ out2=$( cat /sys/class/net/" $basename " /statistics/tx_bytes)
27
+
28
+ # read and remove first element
29
+ out=${out1[0]}
30
+ unset out1[0]
31
+ out1=( ${out1[@]} )
21
32
22
33
# get the difference (transfer rate)
23
- out_bytes=$(( out2 - out 1 ))
34
+ out_bytes=$(( out2 - out ))
24
35
25
36
# convert transfer rate to KB
26
- out_kbytes=$(( out_bytes / 1024 ))
37
+ out_kbytes=$(( out_bytes / 1024 * 2 ))
27
38
28
39
# convert transfer rate to KB
29
40
json_output=" $json_output \" $basename \" : $out_kbytes "
33
44
then
34
45
# add a comma to the line (JSON formatting)
35
46
json_output=" $json_output ,"
36
- fi
47
+ fi
37
48
done
38
49
39
50
# close the JSON object & print to screen
You can’t perform that action at this time.
0 commit comments