Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Mohan Balasundaram tuxfight3r

🏠
Working from home
View GitHub Profile
@tuxfight3r
tuxfight3r / date.sh
Created February 8, 2023 16:59
bash calculate time elapsed between two date timestamps
View date.sh
#!/bin/bash
date1="2023-02-08 10:50:33"
date2="2023-02-08 14:10:33"
date1_seconds=$(date -d "$date1" +"%s")
date2_seconds=$(date -d "$date2" +"%s")
duration=$(( $date2_seconds - $date1_seconds ))
echo "Time Elapsed: $(($duration/3600)) hours $(($duration %3600 / 60)) minutes and $(($duration % 60)) seconds."
@tuxfight3r
tuxfight3r / notes.md
Last active February 8, 2023 16:56
bash format number with thousand separator for busybox shell
View notes.md
For environments where there is no full fledged printf. The below function does a pretty print of numbers with thousand separator

function

#converts given number to pretty format
function pretty_num(){
     awk '{ len=length($0); res=""; for (i=0;i<=len;i++) { res=substr($0,len-i+1,1) res; if (i > 0 && i < len && i % 3 == 0) { res = "," res } }; print res }'|sed -e's/-,\(.*\)/-\1/g'
}

output

@tuxfight3r
tuxfight3r / jump.sh
Last active January 6, 2023 10:14
kubectl jump server via kubectl port-forward
View jump.sh
#!/usr/bin/env bash
# Allows you to connect to remote endpoints via port forward
set -e
TEMP_POD_NAME=db-jump-server
LOCAL_PORT=3307
REMOTE_HOST=prod.abc123.region-1.rds.amazonaws.com
REMOTE_PORT=3306
function cleanup {
@tuxfight3r
tuxfight3r / kcat.md
Last active January 4, 2023 16:40
KafkaCat configuration for AWS MSK
View kcat.md

KafkaCat Configuration for AWS MSK

Set the below environment variable with the following values

NOTE: Kafkacat is renamed to kcat recently and the config variable should be KCAT_CONFIG for version 1.7 onwards.

# you can export the variable or present the config with -F parameter for kafkacat
export KAFKACAT_CONFIG=/home/tools/persistent/kcat/kafkacat_config

Contents of kafkacat configuration

View gist:082ddafb892e3bbf00251b48782413a7
#Simple script to test all the pods liveness/readiness
#creates portforward and curls the endpoint for status
#clears the portforward at the end of the script
#uses bash v3 based implementation.
#Test only the pods which are up.
#!/bin/bash
aggregate_feed="tfeed"
@tuxfight3r
tuxfight3r / gist:b67e94e5a09c61c0c31b00ec0a6e8eb5
Created July 14, 2021 17:19
python decode kubernetes service token (JWT Token)
View gist:b67e94e5a09c61c0c31b00ec0a6e8eb5
# retrieve the default kubernetes service account token
kubectl get secret $(kubectl get serviceaccounts default -o jsonpath='{.secrets[0].name}') -o json|jq -r .data.token |base64 -D
# Decode it using Python (pip install PyJWT)
import jwt
var="encoded.jwt.token"
jwt.decode(var, options={"verify_signature":False})
@tuxfight3r
tuxfight3r / selfsigned-clusterissuer.yml
Last active July 15, 2021 21:08
kube cert-manager cert issuer
View selfsigned-clusterissuer.yml
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: selfsigned-cluster-issuer
spec:
selfSigned: {}
@tuxfight3r
tuxfight3r / dialog.sh
Last active March 25, 2022 16:33
bash script to choose an option with dialog box
View dialog.sh
#!/bin/bash
HEIGHT=10
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="Cluster Options"
TITLE="Select Cluster"
MENU="Choose one of the following options:"
ENV="${ENV:-dev}"
@tuxfight3r
tuxfight3r / kafka-cheat-sheet.md
Created May 7, 2021 17:14 — forked from ursuad/kafka-cheat-sheet.md
Quick command reference for Apache Kafka
View kafka-cheat-sheet.md

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

@tuxfight3r
tuxfight3r / notes.md
Last active March 17, 2021 00:04
validating EC2 pem / ssh key pairs
View notes.md
## Get private key fingerprint for AWS generated key ( will match the id in AWS Console)
$ openssl pkcs8 -in test_key.pem -inform PEM -outform DER -topk8 -nocrypt | openssl sha1 -c
(stdin)= f6:38:9c:53:9c:64:a8:b3:40:23:9f:6c:ed:0e:3d:bf:bf:16:bb:1c

## Get fingerpint from Openssh public key only md5 / sha1
$ ssh-keygen -f test_key.pub -e -m PKCS8 | openssl pkey -pubin -outform DER | openssl md5 -c
(stdin)= 55:b6:90:db:34:29:da:60:68:c9:08:24:f1:9f:c8:4b

(or)