Article 6EC89 Script - Repeat on error

Script - Repeat on error

by
bpalob
from LinuxQuestions.org on (#6EC89)
Good day,

I am pretty new to all this and am trying to do some scripting with IPerf for performance testing.

So far I managed to create a script that runs the iperf command I like to and puts the results I am intereseted in into a text file.

This is the command I use in the script:

iperf3 -c my.iperfserver.com -p 5200-5209 -R -O 3 -t 13 -f m -P 3 --connect-timeout 10000 | echo $(grep -o -P '(?<=SUM]).*(?=receiver)') Download my.iperfserver.com | ts '%d.%m.%Y;%H:%M:%S;' >> /tmp/results.txt

The output in the file reads:

01.09.2023;11:53:33; 0.00-13.00 sec 1.36 GBytes 901 Mbits/sec Download my.iperfserver.com

Now, sometimes the server may be busy or it is not listening. If so, I'd like to loop the command and repeat it after x minutes.

Regretfully it seems the exit code is always successful, no matter the outcome.

I would like to be able to detect when it throws out for example "iperf3: error - the server is busy running a test. try again later" and do exactly this, try again later. Or also if server is unavailable.

My approach now was for instance to say if the command doesn't take more than 5 seconds to complete and go to the next one, it should loop it until it takes more than 5 seconds to complete.

Can anyone give me a hint on how this could be accomplished? Maybe it is the wrong or the unprofessional way,... but I think it would efficiently solve the issue.

Thanks.
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments