Skip to content

Instantly share code, notes, and snippets.

@smj10j
smj10j / tcp-port-scan.sh
Created August 24, 2017 11:56 — forked from cinsk/tcp-port-scan.sh
Wait until TCP ports opened (or closed)
#!/bin/bash
function wait4tcp () {
local nc opt silence op host port ret failed limit tries
local OPTIND OPTARG
limit=100
op="open"
while getopts ":csw:" opt; do
@smj10j
smj10j / filecount.sh
Last active May 20, 2017 14:22
Counts items in a directory
#!/usr/bin/env bash
shopt -s dotglob
function filecount {
DIR=$(dirname "${1:-.}/nonexistentfile")
for item in "${DIR}"/*; do
COUNT=$(($(find "${item}" | wc -l)-1))
if [[ $COUNT -gt 0 ]]; then
echo "${COUNT}: ${item}";
@smj10j
smj10j / vnstat-update.command
Last active May 20, 2017 08:40
Script to run with cron to update vnstati output
#!/usr/bin/env bash
# Fail on any error
set -e
# Debug
# set -x
###########################################################################
####### Set below as appropropriate for your environment ##################
@smj10j
smj10j / dns-timing.sh
Last active May 20, 2017 06:57
Simple "One-liner" DNS-timing
#!/usr/bin/env bash
# set -x
##
## DNS timing "one-liner"
##
function _dns_timing() {
local EMAIL='59766160@opayq.com'
@smj10j
smj10j / mount-nas-volumes.command
Last active February 27, 2017 13:48
Mount AFP volumes on OSX
#!/usr/bin/env bash
# set -e
SERVER='<<myserver>>._afpovertcp._tcp.local'
VOLUMES=( 'share1' 'share2' )
echo ""
echo "$(date)"
@smj10j
smj10j / inject-jquery-bookmark.link
Created January 27, 2017 18:35
Bookmarklet that loads jQuery via the Chrome Dev Console
@smj10j
smj10j / instagram_photo_downloader.js
Created January 27, 2017 08:06
Download all photos from an Instagram page using the Google Chrome dev console
// Download all photos from an Instagram page
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
$('img').each(function(i, el) {
@smj10j
smj10j / show-disk-write-speed.sh
Last active January 21, 2017 02:02
Monitor and print a disk's write speed by doing a simple comparison of the used space over time. Can be useful for network mounts
#!/usr/bin/env bash
DISK="Moody Mona" # Name of a directory mounted in /Volumes
INTERVAL=15
while true; do
s1=$(df -m | grep "$DISK" | awk '{print $3}')
echo "s1=$s1" >&2
sleep $INTERVAL
s2=$(df -m | grep "$DISK" | awk '{print $3}')
@smj10j
smj10j / print-packages-by-size.sh
Last active January 29, 2017 21:42
List all packages on an Ubuntu system sorted by size they take up on disk
#!/usr/bin/env bash
# List all packages on an Ubuntu system sorted by size they take up on disk
sudo dpkg-query --list | awk '{print $2}' | xargs -I% -n1 dpkg-query --status % 2>/dev/null | egrep 'Package: |Installed-Size:' | sed '$!N;s/\n/\t/' | head -n 100 | sort -r -n -k4
@smj10j
smj10j / install_vnstati_crontab.sh
Last active December 27, 2016 10:11
Setup cron jobs for generating bandwidth usage graphs with vnstati
#!/usr/bin/env bash
WWW_DIR=/var/www/html
mkdir -p $WWW_DIR/vnstat
# Generate some graphs now
sudo -u www-data bash -c '
/usr/bin/vnstati -vs -o $WWW_DIR/vnstat/vnstat.png -i ens3 &&