Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
@caruccio
caruccio / bash-regex.md
Last active October 2, 2023 15:00
Bash regex conditionals

In bash you can use [[ pattern =~ regex ]] to match on a conditional:

if [[ "hello world" =~ ^hell ]]; then
  echo Match
else
  echo No match
fi
@caruccio
caruccio / colors.sh
Last active April 26, 2023 00:06
Create env vars for somes ANSI colors
function mkcolor()
{
export $1="${2}" ${1}_E="\[${2}\]"
case "$1" in
BOLD|RESET)
return
;;
*)
export ${1}_B="$(tput bold)${2}" # Bold
@caruccio
caruccio / kubectl-extract
Created January 18, 2023 15:08
Extract secret value
#!/bin/bash
#
# Install: copy to path
# $ cp kubectl-extract /usr/local/bin
#
# Usage:
# $ kubectl extract -n default my-secret
#
@caruccio
caruccio / suspend-process.md
Created December 18, 2022 16:29
Suspend cpu greed process and economize your batery

Create the file stop-proc below:

#!/bin/bash

SIG=${0##*/}    ## basename only (name of the file itself, no dirs)
SIG=${SIG%-*}   ## remove filename suffix. "-*" is a glob pattern ("stop" in this case)
SIG=${SIG^^}    ## UPPERCASE all letters

## read process from command line or use this as default.

Keybase proof

I hereby claim:

  • I am caruccio on github.
  • I am caruccio (https://keybase.io/caruccio) on keybase.
  • I have a public key whose fingerprint is 1B8D F261 E133 2C08 7981 40CC 6C8F D64B E1EF E05E

To claim this, I am signing this object:

@caruccio
caruccio / undistro-demo-eks.sh
Last active October 27, 2021 23:21
Undistro Demo EKS
#!/bin/bash
case "$1" in
-h|--help)
echo "Usage: $0 [phase]"
echo ""
echo "Default phases, in this order: "
echo " download Download all required tools into current directory"
echo " credentials Ask for missing credentials"
echo " create-manager-cluster Create Manager Cluster, used to create \"real\" Clusters"
@caruccio
caruccio / Kubernetes-Stuck-Resources.md
Last active October 14, 2020 20:25
How to identify and remove resources stuck in Terminating state

Namespaces

List all resources within a namespace

NS=some-namespace

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $NS
@caruccio
caruccio / kubectlgen
Created January 3, 2020 15:45
Kubectl Generator - on-the-fly kubectl shortcuts
#!/usr/bin/python
from __future__ import print_function
import sys
def usage(argv):
print('Usage: %s [commands][resources][options][parameters]' % argv[0], file=sys.stderr)
print('\nCommands:', file=sys.stderr)
for s, l in commands:
print(' %s (%s)' % (s, l), file=sys.stderr)
@caruccio
caruccio / pvc-copy.sh
Created October 4, 2019 21:04
Generates an rsync pod to copy between two PVCs
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Usage: $0 pod-name-suffix source-pvc-name destination-pvc-name [rsync options...]"
exit 1
fi
POD_SUFFIX=${1}
PVC_FROM=${2}
PVC_TO=${3}
@caruccio
caruccio / kubectl.md
Created May 7, 2019 17:21 — forked from so0k/kubectl.md
Playing with kubectl output

Kubectl output options

Let's look at some basic kubectl output options.

Our intention is to list nodes (with their AWS InstanceId) and Pods (sorted by node).

We can start with:

kubectl get no