pathway mtu discovery bash script

https://gist.github.com/bneils/8f337bedebffbe3c1bf2c59def7029d2

I wrote pmtud.sh this weekend to get the MTU of a link (or tunnel) quickly, reliably, and without sending a ton of pings. It can do so in about 11 pings per target.

I had fun writing the entire thing in sh, tried making it "POSIX-compliant," but probably failed somewhere since POSIX isn't worded well. The script only needs dig and ping and uses shell built-ins for everything else. It performs a recursive binary search on the MTU search domain and asynchronously queues pings for later.

4 points · 3 comments · view on lemmy.world

3 Comments

crestwave@lemmy.world · 3 pts · 1y (2 replies)

Some stylistic notes

  • The head -1 syntax is obsolete in POSIX, replaced by head -n 1.
  • for filename in $(ls) is inefficient and will break on whitespace. You can use shell globbing for this instead, e.g., for filename in *.
  • A lot of the variables seem to be inconsistently quoted. I recommend running ShellCheck on it, as this can be dangerous (if you set TMPDIR to /tmp/ dir, I believe it will remove /tmp and dir)
mastertraitor@programming.dev · 2 pts · 1y (1 reply)

Saved my bacon with this comment. Fixed a ton of (seemingly) innocuous errors.

IanTwenty@lemmy.world · 1 pts · 1y

100% use shellcheck! Saves so much time. Even better: https://github.com/bash-lsp/bash-language-server