Skip to content

Instantly share code, notes, and snippets.

View snorfsneflin's full-sized avatar

snorf snorfsneflin

  • earth
View GitHub Profile
@snorfsneflin
snorfsneflin / luksOpener.sh
Created January 16, 2016 22:43
Open LUKS container and setup a mapping
#!/bin/bash
# A simple shell to mount disk encryption based parition under Linux.
# Tested on Debian and Ubuntu base NAS servers.
# ----------------------------------------------------------------------------
# Written by Vivek Gite <http://www.cyberciti.biz/>
# (c) 2008 nixCraft under GNU GPL v2.0+
# ----------------------------------------------------------------------------
# Last updated: 05/Dec/2011
# ----------------------------------------------------------------------------
@snorfsneflin
snorfsneflin / LUKS.sh
Created January 16, 2016 22:40
LUKS (Linux Unified Key Setup-on-disk-format) Encryption Examples
#!/bin/bash
#install cryptsetup
apt-get install cryptsetup
#initializes the volume, and sets an initial key or passphrase
cryptsetup -y -v luksFormat /dev/xvdc
#the following command create a mapping
cryptsetup luksOpen /dev/xvdc backup2
@snorfsneflin
snorfsneflin / functions_aptget.txt
Created November 29, 2015 22:37
apt-get shell functions
Update() {
sudo apt-get -qq clean
apt-get -qq update
}
# quietly install space delimited package(s)
Install() {
sudo apt-get install -qq -y --force-yes "$@"
@snorfsneflin
snorfsneflin / ShellTrix.sh
Last active November 11, 2015 07:15
shell trix
#/usr/env bash
#
#create 7 constants using output of date command
readonly year month day hour minutes seconds epoch _ < <(date '+%Y %m %d %H %M %S %s')
#create 7 variables using output of date command
#read year month day hour minutes seconds epoch _ < <(date '+%Y %m %d %H %M %S %s')
echo $year $month $day $hour $minutes $seconds $epoch
#
echo
echo 'optimal cpu load based on number of processors and cores: '
@snorfsneflin
snorfsneflin / ipv4_pattern_matching.txt
Last active January 16, 2016 23:22 — forked from hackingbutlegal/gist:cf4ed2601b7b0fef8157
Regex to match on only valid IPs including local and bcast
grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' file.txt
# match addresses formatted as IP/bits - e.g. 192.168.0.1/24
ip addr sh eth0 | grep -E -o "([0-9]+.){3}[0-9]+/[0-9]+"
@snorfsneflin
snorfsneflin / gist:c4a5a99dc25385031565
Created November 10, 2015 00:31 — forked from hackingbutlegal/gist:a37233367b43bfdce46a
Awk script for device discovery
#
# Class C device discovery in under 5 seconds.
# Notice that it will display information on any MAC address that nmap knows about. It's helpful to keep this updated.
# You can also add any MAC address OIDs that are newer or unknown to the file /usr/share/nmap/nmap-mac-prefixes.
#
# How to call this script:
# nmap -n -sP --excludefile $PROJECT_ROOT/output/known.skip 10.10.100-103.1-255 | awk -f $PROJECT_ROOT/mac-sort.awk
#
BEGIN { PROJECT_PATH="/path/to/scripts"; }
@snorfsneflin
snorfsneflin / polycom-dir.sh
Created November 10, 2015 00:30 — forked from thyrusg/polycom-dir.sh
Generate Polycom XML directory file from FreePBX DB
#!/bin/bash
# Author: Thyrus Gorges
# Date: 2015/03/04
#The MIT License (MIT)
#Copyright (c) <2015> <Thyrus Gorges>
#Permission is hereby granted, free of charge, to any person obtaining a copy
@snorfsneflin
snorfsneflin / copy-default-directory.bash
Created November 10, 2015 00:30 — forked from iloveitaly/copy-default-directory.bash
Some tools for managing polycom phones + asterisk systems
# this assumes you have a default directory defined
find /tftpboot/logs/ | ack 'logs/([^-]+)' --output '$1' | sed '/^$/d' | while read mac
do
cp -f "000000000000-directory.xml" "$mac-directory.xml"
done
@snorfsneflin
snorfsneflin / Polycom reboot
Created November 9, 2015 22:35 — forked from viviandarkbloom/Polycom reboot
Reboot polycom phones
A bash "one-liner" that requires serious explaining:
A Polycom phone will automatically reboot if you change anything in its webui (but you have to change something). This bash/awk/curl loop changes the length of time between sntp resyncs (basically a super-trivial setting) from 86400 seconds (1 day) to 86401. If you run this twice, you would need to change 86401 back to 86400. This is a super-dirty hack. Also note that this sets the sntp server to pool.ntp.org, and the time zone to Pacific (-28800). Although those settings will get overridden if you're setting those in your DHCP scope (which you should), please adjust as necessary. To clarify, $i is an IP address. In this example, I get a list of phone IPs from asterisk and grep the ones I need to reboot, but you can iterate over any list of IPs.
----------
for i in $(asterisk -rx 'sip show peers' | grep 192.168.10 | awk '{print $2}'); do curl -s --user Polycom:456 -H application/x-www-form-urlencoded --referer http://$i/timeConf.htm -d "tcpIpApp.sntp.ad