yet-another-bench-script
yet-another-bench-script copied to clipboard
Rehaul informative text output to take into account the user's terminal window size
Implement a better means of outputting and clearing informative text while the script is running so that if a terminal window is sized small causing the output to be broken up onto multiple lines, the script is able to detect this and clear the correct number of lines.
The script currently only clears the previous line. A helper function will be required due to the dynamic number of characters being output to the terminal (i.e. during iperf test, the character count depends on the provider name and location).
Example garbage output:
iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider | Location (Link) | Send Speed | Recv Speed
| | |
Performing IPv4 iperf3 send test to Clouvider (Attempt #1 of 1Performing IPv4 iperf3 recv test from Clouvider (Attempt #1 ofClouvider | London, UK (10G) | 940 Mbits/sec | 920 Mbits/sec
Performing IPv4 iperf3 send test to Online.net (Attempt #1 of Performing IPv4 iperf3 recv test from Online.net (Attempt #1 oPerforming IPv4 iperf3 recv test from Online.net (Attempt #2 oPerforming IPv4 iperf3 recv test from Online.net (Attempt #3 oOnline.net | Paris, FR (10G) | 932 Mbits/sec | 917 Mbits/sec
Performing IPv4 iperf3 send test to WorldStream (Attempt #1 ofPerforming IPv4 iperf3 recv test from WorldStream (Attempt #1 WorldStream | The Netherlands (10G) | 926 Mbits/sec | 896 Mbits/sec
Performing IPv4 iperf3 send test to Biznet (Attempt #1 of 10).Performing IPv4 iperf3 recv test from Biznet (Attempt #1 of 10Biznet | Jakarta, Indonesia (1G) | 733 Mbits/sec | 213 Mbits/sec
Performing IPv4 iperf3 send test to Clouvider (Attempt #1 of 1Performing IPv4 iperf3 recv test from Clouvider (Attempt #1 ofClouvider | NYC, NY, US (10G) | 884 Mbits/sec | 600 Mbits/sec
Performing IPv4 iperf3 send test to Velocity Online (Attempt #Performing IPv4 iperf3 recv test from Velocity Online (AttemptVelocity Online | Tallahassee, FL, US (10G) | 849 Mbits/sec | 392 Mbits/sec
Performing IPv4 iperf3 send test to Clouvider (Attempt #1 of 1Performing IPv4 iperf3 recv test from Clouvider (Attempt #1 ofClouvider | Los Angeles, CA, US (10G) | 830 Mbits/sec | 355 Mbits/sec
Proposed solution:
- Add function that is passed the informative text to display. This function will count the number of characters in the string before echoing the text to the terminal window
- Store the terminal window size as a variable (
stty size
- https://stackoverflow.com/a/26855761) - Compute the number of lines needed to clear the last informative text that was output to the terminal (i.e. text size / terminal size) and run the
echo -en "\r\033[0K"
command the resulting number of times
- (Optional) In the new function, don't even display anything if the terminal is not running in interactive mode (i.e. output being piped to file or script being run as a cron) (https://serverfault.com/a/146747)