Skip to content

Instantly share code, notes, and snippets.

View lloiacono's full-sized avatar

Leandro Loiacono lloiacono

  • Warehousing1
  • Berlin
View GitHub Profile
@lloiacono
lloiacono / deleteECRImages.sh
Created July 27, 2022 08:18
Delete ECR images keeping only the last N more recent
REPO=$1
KEEP_IMAGES=$2 # number of images you want to remain
aws ecr describe-images --repository-name $REPO --query 'imageDetails[]' \
| jq --raw-output 'sort_by(.imagePushedAt) | reverse | .[].imageDigest' \
| awk "NR > ${KEEP_IMAGES}" \
| xargs -I{} aws ecr batch-delete-image --repository-name $REPO --image-ids imageDigest={}
@lloiacono
lloiacono / kafka-config
Created April 2, 2021 20:42
Kafka retentio
kafka-configs --alter --bootstrap-server localhost:9092 --entity-type topics --entity-name my-input-topic --add-config retention.ms=5000
@lloiacono
lloiacono / mongoDBQueryKiller.js
Created November 17, 2020 16:30
MongoDB query killer
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid
@lloiacono
lloiacono / awk_commands
Created April 30, 2020 21:25
AWK useful
# filter lines by arbitrary value and sorts desc, lines ending with XXXms
grep 'T18:4' /var/log/some/some.log | grep 'ms' | awk '{if($NF-0>500){print $NF-0,$0}}' | sort -rg -k 1 | head -10
# grep text between strings
grep 'T11' /var/log/some/some.log | grep 'someText' | grep -o -P '(?<=TEXT_A).*(?=TEXT_B)' | sort | uniq -c | sort -r | head -50
@lloiacono
lloiacono / rabbitmq_set_get_heartbeat.sh
Created July 4, 2019 09:43
RabbitMQ hearbeat set and get
# Set
rabbitmqctl eval 'application:set_env(rabbit, heartbeat, 1800).'
# Get
rabbitmqctl eval 'application:get_env(rabbit, heartbeat).'
@lloiacono
lloiacono / mx_bukl_lookup.sh
Created February 15, 2019 08:37
Bulk MX lookup with awk and dig
awk '{printf("%s ",$1); system("dig -t mx +short " $0)}' somefile.csv
@lloiacono
lloiacono / fail2ban-allstatus.sh
Created February 15, 2019 08:06 — forked from kamermans/fail2ban-allstatus.sh
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@lloiacono
lloiacono / kafka-tools.sh
Created February 12, 2019 12:31
Kafka-tools
#!/usr/bin/env bash
##
# Source this in your .bashrc
##
set -o pipefail
kafka_avro_schema_id() {
if [ $# -ne 2 ]; then
echo "Usage $0 <bootstrap-server> <topic[:part:[:offset]]>"
@lloiacono
lloiacono / find_match_before_search.sh
Created November 29, 2018 13:56
Find first occurrence of STRING before search STRING
awk '/company_id/ {search_string=$0} /empty_before_import": true/ {print search_string FILENAME " " NR}' error_queue.*.log
@lloiacono
lloiacono / jpeg_optim.sh
Created November 23, 2018 10:14
Jpeg optimization
find . -type f -name '.jpeg' -o -name '.jpg' -exec jpegoptim --strip-all --max=83 -p {} \;