Skip to content

Instantly share code, notes, and snippets.

@creshal
creshal / fix-shell-escapes.patch
Created Oct 29, 2014
Patch against lsyncd version in Debian stable
View fix-shell-escapes.patch
Sanitize mv arguments:
1. Fixes crashes on file names containing `, $ or "
2. Also prevents shell execution of ``, $() … in file names, which can be
used to gain remote shell access as lsyncd's (target) user.
Index: lsyncd-2.0.7/default-rsyncssh.lua
===================================================================
--- lsyncd-2.0.7.orig/default-rsyncssh.lua 2012-02-16 08:24:20.000000000 +0100
+++ lsyncd-2.0.7/default-rsyncssh.lua 2014-10-29 13:59:51.165553255 +0100
@@ -29,14 +29,17 @@
View gist:649e48e11d8addac56e6
# ------------------------------------------------------------------------------
# tlp - Parameters for power save
# Hint: some features are disabled by default, remove the leading # to enable
# them.
# Set to 0 to disable, 1 to enable TLP.
TLP_ENABLE=1
# Seconds laptop mode has to wait after the disk goes idle before doing a sync.
@creshal
creshal / ssh-benchmark
Last active Aug 29, 2015
ssh-benchmark
View ssh-benchmark
#! /bin/bash
pgrep sshd >/dev/null || (echo "Please make sure SSH is running _locally_." && exit 1)
sz=${1:-128}
testfile=$(mktemp -p /run/user/$UID)
filename=$(basename $testfile)
echo "Generating temporary file, $sz MiB size. Supply a size argument to change. (Should be small enough to fit in RAM twice.)"
View gist:3089059
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', '-g', 'jshint' ]
2 info using npm@1.1.33
3 info using node@v0.8.1
4 verbose config file /root/.npmrc
5 verbose config file /usr/local/etc/npmrc
6 verbose config file /usr/local/lib/node_modules/npm/npmrc
7 verbose read json /usr/local/lib/package.json
8 verbose read json /usr/local/lib/package.json
9 verbose cache add [ 'jshint', null ]
@creshal
creshal / gist:3089077
Created Jul 11, 2012
1st npm debug log
View gist:3089077
info it worked if it ends with ok
verbose cli [ '/usr/local/bin/node',
verbose cli '/usr/local/bin/npm',
verbose cli 'install',
verbose cli '-g',
verbose cli 'jshint' ]
info using npm@1.1.0-beta-4
info using node@v0.8.1
verbose config file /root/.npmrc
verbose config file /usr/local/etc/npmrc
View backup-rsync
#! /bin/python
import sys,os,time,glob,shutil
import subprocess as sp
def backup (src,dst):
src = sys.argv[1]
exclude_file = os.path.join (src,'.backup-exclude')
dst = sys.argv[2]
dst_dir = os.path.join (dst,'%i'%time.time())
lnk_dir = get_old_backups (dst)[-1]
@creshal
creshal / check_nrpe_ssh.sh
Last active Dec 23, 2015
Tunnel Nagios NRPE over SSH
View check_nrpe_ssh.sh
#! /bin/bash
# Author: Sven Schwedas <sven.schwedas@tao.at> for TAO Software
# Published under MIT license
function freeport () {
# pick random port to keep collision chance minimal, ideally we don't want
# to enter the loop at all
pnum=$(shuf -i $(sed 's/\t/-/' /proc/sys/net/ipv4/ip_local_port_range) -n 1)
while nc -z 127.0.0.1 $pnum; do
let pnum++