In this script for monitoring the real-time network port rate, there is an error on lines 21 and 22:
#!/bin/bash
#Modified by [email protected]
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1
ethn=$1
while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME"
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi
if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi
echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` "
done
Revised document
#!/bin/bash
#Modified by [email protected]
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1
ethn=$1
while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME"
RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre))
if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi
if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi
echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` "
done
The reason is that when the value of $is taken, only variables need to be followed in the brackets (variables can be calculated by themselves), and it is not necessary to take the value of variables in the brackets
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
change to:
RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre))
And then there’s no error~~~
Similar Posts:
- If conditional statement in Bash reports an error [: missing `] ‘
- How to Replace log4j with shell Script in Bulk
- How to Solve Sudo Echo Error: Permission denied
- TypeError: not enough arguments for format string
- java.net.NoRouteToHostException: Cannot assign requested address
- Kafka official kafka-server-start.sh cannot close Kafka process solution
- Execute the Jmeter Script Error: .org.apache.http.conn.httphostconnectexception: XXXX failed: unable to specify the solution of the requested address (Connect failed)
- Tokudb engine Install Error: error: percona server is not running with jemalloc
- Linux Programmer Error: /bin/bash: No such file or directory [How to Solve]
- Shell script execution error [: 0: unary operator expected