Skip to content

Instantly share code, notes, and snippets.

@fbettag
fbettag / juniper-junos-bgp-peers-to-yaml.awk
Last active January 13, 2021 20:23
AWK script which takes the output of "show configuration protocols bgp" on a Juniper Router and converts it into yaml. Can be used to convert an old configuration on a router into Ansible JunOS style. Should be adapter to your configuration style and case.
#!/usr/local/bin/gawk -f
/neighbor|peer-as|description|apply-group|authentication-key/ {
out="";
for (i=7; i<=NF; i++) {
out=out" "$i
}
gsub(/"/, "", out);
if ($6 == "neighbor") {
@fbettag
fbettag / cwmrc
Created January 17, 2019 11:48
tiling windows in cwm and other managers that don't support top-right, top-left etc. Works with multiple monitors using mmutils.
bind-key 4-Up "bin/tile.sh top"
bind-key 4-Down "bin/tile.sh bottom"
bind-key 4-Left "bin/tile.sh left"
bind-key 4-Right "bin/tile.sh right"
bind-key C4-Up "bin/tile.sh top-right"
bind-key C4-Left "bin/tile.sh top-left"
bind-key C4-Down "bin/tile.sh bottom-left"
bind-key C4-Right "bin/tile.sh bottom-right"
@fbettag
fbettag / migrate.sh
Last active August 5, 2018 18:23
SmartOS Zone Migration script that takes care of installing the required image on the target compute node. Just keep this script on the headnode.
#!/bin/sh
# Franz Bettag <franz@bett.ag> - August 2018
# Script script migrates Zones/KVMs on Joyent SmartOS from one node to another.
# First it creates a new VM on the target from the same config as the original VM.
# It leaves out the nics section as to not run into any conflicts with the currently running machine.
# We then zfs send an intial snapshot of the original VM to the target.
# Then we shutdown the original VM and create another snapshot.
# After the last snapshot has been transferred, we update the new VM with nics and start it up.
# Cleanup of course.
#
@fbettag
fbettag / mdata.sh
Created July 25, 2018 19:59
rudder agent hook script to be placed into /var/rudder/hooks.d
#!/bin/sh
# All available metadata within the sdc: namespace gets converted into vars.
VARS="uuid server_uuid datacenter_name alias billing_id brand cpu_shares create_timestamp dns_domain hostname image_uuid last_modified limit_priv max_locked_memory max_lwps max_physical_memory max_swap owner_uuid quota state tmpfs zfs_io_priority zonename zonepath"
E="{"
# The sdc: namespace.
for key in $VARS
do
#!/bin/sh
LINES=150
LOG=/logs/everything.log
IGNORE="'U7PG2|cron|no matching key|[Ii]nvalid user|preauth|Timeout before auth|service=retention|-- MARK --|Log statistics|ntpd|tsm1|last message repeated'"
CURLOG="egrep -ve $IGNORE $LOG | tail -n $LINES"
NOWLOG="tail -Fn 0 $LOG | egrep -ve $IGNORE"
ssh tail@data "$CURLOG && $NOWLOG" | ccze -A
@fbettag
fbettag / .Xmodmap
Created March 30, 2018 17:29
Logitech G610 xmodmap bindings for multimedia keys
! logitech g610 multimedia keys
keycode 170 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 92 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 189 = XF86AudioPrev NoSymbol XF86AudioPrev
keycode 190 = XF86AudioNext NoSymbol XF86AudioNext
keycode 184 = XF86AudioPlay XF86AudioPause XF86AudioPlay XF86AudioPause
keycode 207 = XF86AudioMute NoSymbol XF86AudioMute
keycode 147 = XF86AudioStop XF86Eject XF86AudioStop XF86Eject
@fbettag
fbettag / freebsd dalmatiner db 0.3.3 port - almost working
Created November 15, 2017 05:50
Almost working port of dalmatinerdb. Works when you make package manually, but doesn't when poudriere tries to do offline/cleanroom builds. good luck, i'm out of time on this. HOW CAN A DATABASE CLAIM TO BE OPTIMIZED FOR ZFS AND NOT HAVE A WORKING FREEBSD PORT? WTF GUYS
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# databases
# databases/dalmatinerdb
# databases/dalmatinerdb/Makefile
@fbettag
fbettag / gist:fe02609c40516a58dd1e82241a65597a
Created September 14, 2017 21:43
create logstash.conf mutations/conversions for INT and NUMBER out of your patterns folder
cat patterns/*/*|egrep -oe '(BASE10|INT|NUMBER|BASE16FLOAT):[^}]+'|grep :|sort|uniq |awk -F: '{if($1 == "NUMBER"||$1 == "BASE16FLOAT") print "\""$2"\" => \"float\""; else print "\""$2"\" => \"integer\""}'
@fbettag
fbettag / dump-and-load.sh
Last active September 9, 2017 11:27
SOLR dump and restore script using plain sh and bc, does pagination and dumps to file, also forks for insertion
#!/bin/sh
#
# Dumps a subset of one Solr core and loads it into another one.
#
if [ $# -lt 4 ]; then
echo "Usage: $0 <source> <target> <limit> [core1 core2...]"
echo " $0 http://source.solr:8983/solr http://target.solr:8983/solr 100000 core1 core2"
exit 1
fi
@fbettag
fbettag / finddisks.sh
Last active December 5, 2015 16:56
Find harddisks programmatically in shell under FreeBSD while also identifying SMART capability
#!/bin/sh
DEVICES=`/sbin/camcontrol devlist | /usr/bin/egrep -oe '\(\w*\d*'| /usr/bin/sed -e 's;^(;;g'`
for DEVICE in $DEVICES; do
NEED_SMART=`/sbin/camcontrol identify $DEVICE | /usr/bin/egrep -coe '^SMART.*yes.*no.*'`
if [ $NEED_SMART -eq 1 ] && [ -f "/usr/local/sbin/smartctl" ]; then
/usr/local/sbin/smartctl -s on /dev/$DEVICE
[ $? -eq 0 ] && echo "Enabled SMART for $DEVICE" 1>&2 # output to STDERR so people see it while piping ;)
fi