I want to log the receive data speeds of a NIC card in linux into a text file. What is the best way to do something like this (not afraid of using terminal)
Asked
Active
Viewed 715 times
1 Answers
0
#!/bin/bash
if [[ -z ${1} ]]; then
echo "You must provide an interface to monitor"
exit
fi
nic="${1}"
while true; do
SPEED=$(cat /proc/net/dev | grep $nic |awk '{$1=$1};1' | cut -d' ' -f 2)
TIME=$(date +%s)
echo "$TIME,$SPEED" >> /tmp/log-bandwidth-$nic-$(date '+%Y-%m-%d')
sleep 5
done
If you create this as a file, say bandwidth-monitor.sh
, then you can run it and provide the network interface to monitor:
bash bandwidth-monitor.sh eno1
This will create a file in /tmp
(which you can modify. For example:
tail -f /tmp/log-bandwidth-eno1-2022-06-03

earthmeLon
- 11,247