Skip to content

Instantly share code, notes, and snippets.

View purpleidea's full-sized avatar

James purpleidea

View GitHub Profile

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

$brickdir = '/storage1';
$glusterdir = '/storage';
// if you only want to copy certain directories, specify them here
$directories = array('apt-mirror', 'apt-repo', 'downloads', 'torrents', 'storage');
$max_copies = 100; // concurrency
$file_size = 0; // total copied file size
@purpleidea
purpleidea / systemd-start-and-wait.go
Created May 4, 2018 13:51 — forked from ghedo/systemd-start-and-wait.go
Start a systemd unit and wait until it stops
package main
import "log"
import "os"
import "github.com/docopt/docopt-go"
import "github.com/godbus/dbus"
const target string = "org.freedesktop.systemd1";
const object string = "/org/freedesktop/systemd1";
@purpleidea
purpleidea / main.go
Created May 7, 2018 15:04 — forked from ast/main.go
Using epoll with go. Packages like fsnotify does not work with sysfs. Then you need epoll, poll or select.
package main
import (
"golang.org/x/sys/unix"
"log"
"os"
)
func main() {
file, err := os.Open("/sys/class/somefile")
@purpleidea
purpleidea / epoll.go
Created May 7, 2018 18:50 — forked from ast/epoll.go
Minimal viable epoll package for go
package epoll
import (
"golang.org/x/sys/unix"
"os"
)
type Op uint32
const (
@purpleidea
purpleidea / terraformer.go
Created May 11, 2018 22:57 — forked from gosuri/terraformer.go
Using terraform with go
package terraformer
import (
"bytes"
"errors"
"path"
"path/filepath"
"...runtime"
"...store"
@purpleidea
purpleidea / SMBDIS.ASM
Created June 30, 2018 02:10 — forked from 1wErt3r/SMBDIS.ASM
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no

In a terminal start a server.

$ python -m SimpleHTTPServer 8000

In another terminal set up the cgroups freezer.

@purpleidea
purpleidea / capslock_super_esc.md
Created November 18, 2018 01:30 — forked from bendavis78/capslock_super_esc.md
Mapping Caps Lock to simultaneous Esc and Super (Mod4)

Mapping Caps Lock to simultaneous Esc and Super (Mod4)

The CAPS key can be mapped to an escape key when pressed once, and a super (mod4) key when used in combination with other keys.

Create the file /usr/share/X11/xkb/symbols/custom_opts with the following:

// Make Caps an additional Escape
hidden partial modifier_keys
xkb_symbols "super_esc" {

key { [ Escape ] };