This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./redir.sh 3>&1 >&2 | while read line; do | |
> echo $line go\! | |
> done | |
Hey! | |
Ho! | |
Let's go! | |
$ cat redir.sh | |
#!/bin/bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Net::LDAP::Wrapper; | |
use strict; | |
use parent 'Net::LDAP'; | |
my $_base; | |
sub new { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $cmd = '/bin/cat /proc/cpuinfo'; | |
my $chan = $ssh->channel; | |
$chan->exec($cmd); | |
my $buf; | |
my @poll = ( { handle => $chan, | |
events => [ 'in', 'ext', 'channel_closed' ], }, | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |