Created
April 21, 2021 10:29
-
-
Save KiNgMaR/4be570682feecc29db20d661f0628334 to your computer and use it in GitHub Desktop.
Bash script that atomically selects a port from the range 30000-40000 on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref: https://unix.stackexchange.com/a/274499 | |
# | |
RANDOM_PORT=$(expr `(flock -x 200; cat /tmp/nextport; expr \( \`cat /tmp/nextport 2>/dev/null\` + 1 \) % 10000 > /tmp/nextport;) 200>/tmp/nextport.lock` + 30000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment