Posts

Showing posts from April, 2020

To get a random available port in your *nix-based machine

For example, If I want to get a random port from the 3000-3999 port pool, I would run the following command in the terminal: comm -23 <(seq 3000 3999 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1

Manipulate your yaml file with yq

I like to play with bash shell especially when I have to manipulate template files of some sort on the go (dynamically). yq is a great tool I just figured out that can help me to generate SAM [1] template.yaml file based on some business logic. The great thing about yq is that I don't have to install it to be able to run it with the help of docker. So, add this to my bash script yq ( ) { docker run --rm -i -v ${PWD} :/workdir mikefarah/yq yq $@ } and than I can use yq as if I installed it, for example: yq d template.yaml 'Resources.AllOutboundSG' Read [2] to know more about how to use yq. References: [1]  https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html [2]  https://mikefarah.gitbook.io/yq/