Skip to content

Instantly share code, notes, and snippets.

@mellertson
mellertson / findgrep
Last active June 10, 2020 04:39
findgrep - finds files matching a file pattern and then grep found files using a regex pattern
#!/bin/bash
RED="\e[31m"
GREEN="\e[32m"
BOLD="\e[1m"
ITALIC="\e[3m"
UNDERLINE="\e[4m"
END="\e[0m"
function usage {

sshx - Run a Local Script over SSH with Interactivity

Sometimes you want to run a bit more than just one command over ssh, and you also want to maintain interactivity to the processes that you launch. Usually you could just do ssh -t <host> "foo; bar; fish; paste" however that can quickly become unwieldly, especialy if it is more than just a sequence of commands. You also can't use cat my_script | ssh <host> /bin/bash because then you loose your stdin and thus your interactivity.

However, there is a way to achieve our goal using the first form above. Consider that the maximum command line length is usually more than 2MB (see getconf ARG_MAX). Thus, we convert our entire script into a base64 encoded string with cat my_script | base64 and then call ssh -t <host> /bin/bash "<(echo <base64 string> | base64 --decode)". In this way the entire script is sent to the host in the command buffer, and so long as our total command length is less than 2MB, it will run.

@bmatthewshea
bmatthewshea / show_ssl_expire
Last active March 1, 2023 22:13
Retrieve/Check SSL certificate expiration date(s)
#!/bin/bash
# By B Shea Dec2018 & Mar2020
# https://www.holylinux.net
# Test for OpenSSL - if not installed stop here.
if ! [[ -x $(which openssl) ]]; then
printf "\nOpenSSL not found or not executable.\nPlease install OpenSSL before proceeding.\n\n"
exit 1
fi
@nfekete
nfekete / wsl-fix-resolvconf.sh
Created August 8, 2018 03:05
Fix resolv.conf in Windows Subsystem for Linux, when WSL doesn't correctly generate it.
#!/bin/bash
TMP=`mktemp`
trap ctrlC INT
removeTempFiles() {
rm -f $TMP
}
ctrlC() {
@umer936
umer936 / main.js
Last active July 13, 2020 15:42
Javascript bookmarklet to strip tracking tags in URLs for better bookmarking
javascript: void
function() {
var url = location.search;
if (url) {
var each = url.slice(1).split("&");
console.log("Stripping query parameters:", each);
var leave = each.filter(function(url) {
return "utm_" !== url.substr(0, 4) &&
"mc_" !== url.substr(0, 3) &&
"ct" !== url.substr(0, 2) &&
@josh-padnick
josh-padnick / README.md
Last active March 16, 2024 15:19
Manually Edit AWS Console "Switch Role" Configuration in Bash

Manually Edit AWS Console "Switch Role" Configuration in Bash

Motivation

At Gruntwork, we work with multiple software teams. That means we have to modify the "Switch Role" history multiple times. But the only way to do that today is to delete your cookie and clear all AWS Console saved settings. That got old after a while, so these instructions enable you to modify the "Switch Roles" configuration directly.

The Big Picture

@FutureSharks
FutureSharks / splunk-daemonset.yaml
Last active July 8, 2020 19:31
Creates a Kubernetes DaemonSet that will monitor container logs and forward them to a Splunk Indexer
# Create using kubectl:
# $ kubectl create -f splunk-daemonset.yaml
#
# You should also add config on your indexer to deal with the json formatted files:
# https://answers.splunk.com/answers/148307/how-to-parse-and-extract-json-log-files-in-splunk.html
#
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: splunk-forwarder
# Note: ~/.ssh/environment should not be used, as it
# already has a different purpose in SSH.
env=~/.ssh/agent.env
# Note: Don't bother checking SSH_AGENT_PID. It's not used
# by SSH itself, and it might even be incorrect
# (for example, when using agent-forwarding over SSH).
agent_is_running() {
@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@andrewwatts
andrewwatts / xmltool.py
Created September 30, 2010 06:50
a python xmltool in the spirit of python's json.tool
#!/usr/bin/env python
# encoding: utf-8
"""
In the spirit of python's json.tool, provide a command line
utility to pretty print XML.
Usage ():
$ echo "<book><title>Oliver Twist</title></book>" | python -m xmltool
<?xml version="1.0" encoding="utf-8"?>