Skip to content

Instantly share code, notes, and snippets.

View lgaggini's full-sized avatar

Lorenzo Gaggini lgaggini

View GitHub Profile
@lgaggini
lgaggini / check_password_expiry.sh
Created August 18, 2021 14:47
Calculates the password expiration date based on pwdChangeTime and validity in days
#!/bin/bash
# Author: Lorenzo Gaggini
#
# Calculates the password expiration date based on pwdChangeTime
# validity in days
usage() {
cat <<USAGE
@lgaggini
lgaggini / check_file_perms.sh
Last active June 29, 2020 13:59
Check if the target path has the expected permissions
#! /bin/bash
# Author: Lorenzo Gaggini - lorenzo.gaggini@dada.eu
# Check if a the target path has the expected permissions
#
# Usage: ./check_file_perms.sh -t target_path -p expected_permissions
function usage()
{
@lgaggini
lgaggini / account_credentials.py
Created June 4, 2018 12:23
Retrieve accounts info from pass (passwordstore.org) to be used in dotfiles instead of clear passwords: pass is on the first line, username on the second one.
#! /usr/bin/env python2
# Author: Lorenzo Gaggini
# Version: 0.1
#
# Retrieve accounts info from pass (passwordstore.org)
# to be used in dotfiles instead of clear passwords:
# pass is on the first line, username on the second one.
from subprocess import check_output
import sys
@lgaggini
lgaggini / git-author-rewrite.sh
Created March 28, 2018 12:20
bash snippet to rewrite commit story author info
#!/bin/sh
git filter-branch -f --env-filter '
OLD_EMAIL="old@email.net"
CORRECT_NAME="my name"
CORRECT_EMAIL="new@email.net"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@lgaggini
lgaggini / cluster_info.sh
Created March 21, 2018 10:35
Get cluster / host info by ansible and ansible-cmdb
#! /bin/bash
# Author: Lorenzo Gaggini
# Version: 0.1
#
# Get cluster info by ansible and ansible-cmdb
#check input
if [ "$#" -ne 1 ]; then
echo "usage: cluster_info.sh group | host"
exit 1
@lgaggini
lgaggini / reroute_primary.sh
Created March 13, 2018 07:32
Simple script to force reallocation of unassigned primary shard
HOST={{ some_master_hostname/ip address }}
PORT=9200
TO_NODE="{{ destination_node }}"
curl "http://$HOST:$PORT/_cat/shards" | grep UNAS | awk '{print $1" "$2}' | while read var_index var_shard; do
curl -XPOST "http://$HOST:$PORT/_cluster/reroute?pretty" -H 'Content-Type: application/json' -d "
{
\"commands\" : [
{
\"allocate_stale_primary\":
@lgaggini
lgaggini / check_mod_file_glob.sh
Created December 15, 2017 10:05
Check if a file matching file pattern in a path matching path pattern was modified in the last N minutes
#!/bin/bash
#
# Author: Lorenzo Gaggini - lorenzo.gaggini@dada.eu
# Check if a file matching file pattern in a path matching path
# pattern was modified in the last N minutes and it raise a CRITICAL
# if it's the case, it's OK otherwise.
#
# Usage: ./check_mod_file_glob.sh -p path_pattern -f file_pattern -c minutes
function usage()
@lgaggini
lgaggini / tmux_splitted_pager
Last active October 25, 2017 13:46
wrapper to use w3m as pager / browser opening a right panel in tmux
#!/bin/sh
# https://cyprio.net/wtf/2012-08-13-using-newsbeuter-with-tmux-and-w3m-to-read-news.html
W3M='/usr/bin/w3m'
# If the window has only one pane, create one by splitting.
pane_count=`tmux list-panes -F '#{line}' | wc -l`
if [ $pane_count -lt 2 ]; then
tmux split-window -h
fi
@lgaggini
lgaggini / naughty-send
Last active May 24, 2018 14:47
Simple wrapper bash script to create notification feeding naughty by awesome-client
#! /bin/bash
# Author: Lorenzo Gaggini
# Version: 0.2
#
# Create a naughty awesome wm notification by title
# and message on secondary (big) screen
# init env for cron/at execution
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export DISPLAY=:0
@lgaggini
lgaggini / check_docker_container.sh
Last active May 10, 2017 08:33 — forked from ekristen/check_docker_container.sh
Bash Script for Nagios to Check Status of Docker Container
#!/bin/bash
# Author: Erik Kristensen, Lorenzo Gaggini
# Email: erik@erikkristensen.com, lorenzo.gaggini@dada.eu
# License: MIT
# Nagios Usage: check_nrpe!check_docker_container!_container_id_
# Usage: ./check_docker_container.sh _container_id_
#
# The script checks if a container is running and grab performance data
# OK - running