Skip to content

Instantly share code, notes, and snippets.

View LozanoMatheus's full-sized avatar
💭
with great changes comes great improvements

Matheus Lozano LozanoMatheus

💭
with great changes comes great improvements
View GitHub Profile
@LozanoMatheus
LozanoMatheus / example_switching_version_asdf.sh
Created February 17, 2021 19:36
How to switch between runtime versions on Bash, Zsh or Fish
## Install
asdf plugin add terraform
asdf install terraform 0.13.0
asdf install terraform 0.14.7
asdf install terraform 0.12.29
##
## Command
terraform version
##
@LozanoMatheus
LozanoMatheus / example_asdf.sh
Last active February 17, 2021 19:25
How to use asdf to manage multiple runtimes and switch between versions
## Add the awscli plugin
asdf plugin add awscli
## List the awscli version
asdf list-all awscli
## Install awscli version 2.1.27
asdf install awscli 2.1.27
## or to install the latest of awscli
asdf install awscli latest
@LozanoMatheus
LozanoMatheus / 01-test_vars_inside_function.sh
Last active February 11, 2021 01:25
Bash variables - Explaining their differences - defining the vars inside of a function
#!/usr/bin/env bash
function test_vars(){
declare -g declare_g="declare_g_output"
declare -x declare_x="declare_x_output"
declare declare_only="declare_only_output"
export export_only="export_only_output"
local local_only="local_only_output"
@LozanoMatheus
LozanoMatheus / 01-test_vars_outside_function.sh
Last active February 11, 2021 01:24
Bash variables - Explaining their differences - defining the vars outside of a function
#!/usr/bin/env bash
function print_vars(){
echo "func_declare_g->${declare_g}<-"
echo "func_declare_x->${declare_x}<-"
echo "func_declare_only->${declare_only}<-"
echo "func_export_only->${export_only}<-"
# echo "func_local_only->${local_only}<-"
@LozanoMatheus
LozanoMatheus / example_trap.sh
Last active February 20, 2022 01:41
Using Bash trap when a command fails
#!/usr/bin/env bash
set -E
function log() {
local msg_args=("${@}")
local timestamp="$(date +'%Y-%m-%d %T')"
declare -u log_level="${msg_args[0]}"
local message="${msg_args[@]:1}"
@LozanoMatheus
LozanoMatheus / 01-verify_oidc.sh
Last active January 22, 2021 19:58
Using AWS IAM Role in a EKS / Kubernetes POD
## First of all, check if you already have an OpenID Connect
### List your EKS cluster OIDC URL
aws eks describe-cluster --name <CLUSTER_NAME> --query "cluster.identity.oidc.issuer"
#### Output
https://oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>
### List your
aws iam list-open-id-connect-providers
@LozanoMatheus
LozanoMatheus / cleaning_docker.sh
Created December 17, 2020 22:00
Cleaning Docker images, networks, volumes, etc
## Cleaning Docker images, networks, volumes, etc
function flush_docker() {
[[ "${1}" == "all" ]] && local delete_docker_volumes="--volumes"
docker system df
docker rm -f $(docker ps -qa) &> /dev/null
Docker_Prune_All="$(docker system prune --all ${delete_docker_volumes} --force)"
tail -1 <<< "${Docker_Prune_All}"
}
@LozanoMatheus
LozanoMatheus / ssh-config
Last active December 11, 2020 09:01
Accessing an EC2 via SSH using AWS SSM
## A basic set up of ~/.ssh/config in your local machine/client
## ssh i-0a1b2c3d4e5f6g7h8i9
Host i-*
User ec2-user
ProxyCommand bash -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
IdentityFile ~/.aws/test-mlozano001.pem
## In this case, it will search for a running instance that has the Tag:Name set to example-ssh-via-aws-ssm
@LozanoMatheus
LozanoMatheus / ssh_ec2_ssm.sh
Created December 10, 2020 19:41
Accessing an EC2 via SSH using AWS SSM
aws ssm start-session --target ${Instance_Id}
## or
ssh ${Instance_Id}
@LozanoMatheus
LozanoMatheus / get_ip.sh
Created November 30, 2020 21:41
Get Linux IP without any tool
#!/usr/bin/env bash
## Get the primary and secundary IPs
awk '/\|--/ && !/\.0$|\.255$/ {print $2}' /proc/net/fib_trie
## Get only the primary IPs
awk '/32 host/ { print i } {i=$2}' /proc/net/fib_trie