Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
# https-ssh-switch.pl: Turn on https → ssh redirect for the source IP of
# an http request. Allows you to dodge some aggressive firewalls resp.
# paywalls.
# Sample sudo rule: www-data ALL=(root) NOEXEC:NOPASSWD: /sbin/iptables -t nat -I PREROUTING -i [[\:alnum\:]]* -s [[\:digit\:].]* -p tcp --dport 443 -j REDIRECT --to-ports 22
# 2014-02-10 Daniel Albers <[email protected]>, released under GPL license
# TODO: IPv6 support
use strict;
use warnings;
@AlD
AlD / rrd-32-to-64-bits.sh
Last active December 16, 2023 18:13
Fix „ERROR: This RRD was created on another architecture“ on Debian
debootstrap --arch=i386 --include=rrdtool stable /tmp/rrdtool-i386 &&
mount --bind /var /tmp/rrdtool-i386/var &&
find /var -mount -type f -name \*.rrd |
while read rrd; do
td=$(mktemp -d)
linux32 chroot /tmp/rrdtool-i386 rrdtool dump "$rrd" > $td/xml &&
rrdtool restore $td/xml $td/rrd &&
cp $td/rrd "$rrd"
rm $td/{xml,rrd}
rmdir $td
$ ./redir.sh 3>&1 >&2 | while read line; do
> echo $line go\!
> done
Hey!
Ho!
Let's go!
$ cat redir.sh
#!/bin/bash
@AlD
AlD / poor_mans_at.sh
Created June 27, 2013 12:23
when you have no atd, this is handy
#!/bin/bash
# Basic bash implementation of at(1). Obviously doesn't survive a reboot.
poor_mans_at() {
delay=$[$(date +%s -d "$*") - $(date +%s)]
if [[ ! "$delay" -ge 0 ]]; then
echo "error: invalid time specification" >&2
return 1
fi
mapfile cmds
( sleep $delay && eval "${cmds[@]}" )&disown
@AlD
AlD / Wrapper.pm
Created March 14, 2013 16:12
Add a default search base to Net::LDAP via new(base => $base)
package Net::LDAP::Wrapper;
use strict;
use parent 'Net::LDAP';
my $_base;
sub new {
@AlD
AlD / gist:3900298
Created October 16, 2012 16:14
Net::SSH2 poll
my $cmd = '/bin/cat /proc/cpuinfo';
my $chan = $ssh->channel;
$chan->exec($cmd);
my $buf;
my @poll = ( { handle => $chan,
events => [ 'in', 'ext', 'channel_closed' ], },
);
my $from = [ 'links', 'vlans' ];
my $what = [ 'links.ifname', 'vlans.vlanid' ];
my $where = { 'links.neighbour' => { '=' => \"vlans.device",
'like' => $neighbour . '%'
},
'links.device' => $device,
};
my $order = '';
my $result = $dbh->select($from, $what, $where, $order);
$ cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
my $text;
$text = $self->render_partial('a', body => rand());
$text .= $self->render_partial('b', body => rand());
@AlD
AlD / solaris-pkgrm-broken-pkgs.sh
Created September 11, 2012 12:33
remove broken packages (unresolved dependencies) from a Slowlaris host
#!/usr/bin/env bash
pushd /var/sadm/pkg &&
for pkg in *; do
[ -f $pkg/install/depend ] &&
egrep '^[PR] ' $pkg/install/depend |
tr '[:space:]' ' ' |
cut -d\ -f2 |
while read dep; do
if ! pkginfo -q $dep; then
#!/bin/bash
set -u
basepath="${1:-/}"
read device rest < <(df -P "$basepath" | grep ^/)
mount | grep "^${device} " | while read dev on mountpoint rest; do
[[ "$mountpoint" != "${basepath}" ]] && echo "$mountpoint"
done