Skip to content

Instantly share code, notes, and snippets.

@jeremyfix
Last active May 28, 2019 10:08
Show Gist options
  • Save jeremyfix/7a8cb509af0f21c9038256b45331e912 to your computer and use it in GitHub Desktop.
Save jeremyfix/7a8cb509af0f21c9038256b45331e912 to your computer and use it in GitHub Desktop.
Get a free port in a Makefile
#!/bin/bash
# Provided by https://superuser.com/a/1293762/622572
comm -23 <(seq 10000 65535) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep "[0-9]\{1,5\}" | sort | uniq) | shuf | head -n 1
$(eval PORT = $(shell ./get_free_port.sh))
testbidule:
@echo "I found a free port number : " $(PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment