Skip to content

Instantly share code, notes, and snippets.

@sqqqrly
sqqqrly / Makefile-help
Last active December 9, 2021 15:42
Makefile-help
# ##@ Help Group Name
# .PHONY: recipe_name
# To pick up the recipe name, use:
# recipe_name: ## Recipe help.
# @echo -e $(_begin)
# ...works...
# @echo -e $(_finish)
# Use color in Makefiles.
# Set this before including this file in other Makefiles.
kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
annotations:
kubernetes.io/description: allow hostpath and host network to be accessible.
generation: 1
name: iboxcsiaccess
selfLink: /apis/security.openshift.io/v1/securitycontextconstraints/iboxcsiaccess
allowHostDirVolumePlugin: true
allowHostIPC: false
@sqqqrly
sqqqrly / trapping.sh
Last active April 1, 2020 21:40
Trapping signals / awk, without leaning toothpicks
#!/bin/bash
function shutdown {
echo "Shutting down $PROGRAM"
local -r QUIT="SIGQUIT"
# TODO - What is the process is not found?
local -r PID="$(ps aux | awk '( $0 ~ "/usr/bin/clickhouse-server" ) {print $2}')"
echo "pid: $PID"
#kill -s 3 "$PID"
echo "Done killing"
@sqqqrly
sqqqrly / bounce_services.out
Last active February 28, 2020 20:22
A utility to restart select services and/or truncate log files.
$ ./bounce_services.sh
=== What would you like to do with openstack services?
services --> logs:
openstack-nova-compute-8202E4C_10B54ER.service --> /var/log/nova/nova-compute-8202E4C_10B54ER.log
openstack-cinder-volume-generic0.service --> /var/log/cinder/volume-generic0.log
none --> /tmp/infinidat_logit.log
1) truncate logs only 3) truncate and restart
2) restart services only 4) exit
@sqqqrly
sqqqrly / output
Last active August 29, 2019 22:55
Filter away sensitive strings in py3 from stdout and other stream-like objects. Here we are filtering stdout, stderr and file stream.
[I] ➜ ./redactor.py
data out: ********
data err: ********
data out: ********
data err: ********
[I] ➜ cat test.txt
data: ********
data: ********
@sqqqrly
sqqqrly / create_veth.sh
Last active June 20, 2019 17:54
Create a veth using dummy module without setting an IP
#!/usr/bin/env bash
# Create a dummy veth.
# To add an addr:
# ip addr add $addr/24 brd + dev $veth label $veth:0
# To remove $veth:
# if addr set:
# ip addr del $addr/24 brd + dev eth10 label veth5:0
# ip link delete $veth type dummy
# rmmod dummy

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th