Skip to content

Instantly share code, notes, and snippets.

@tsaavik
tsaavik / mp3-tuner.sh
Last active June 4, 2026 16:05
Inspired by the tuner scripts we used at mp3.com, this sets some performance options for hard disks, and has some specific optimizations for SSD/NVMEs
#!/bin/bash
# Tweak hard drive performance stuff
for drive in sd{a..z}; do
if [[ -e /dev/${drive} ]] ;then
#increase readahead buffer on sata devices
/sbin/blockdev --setra 2048 /dev/${drive}
echo 1024 > /sys/block/${drive}/queue/read_ahead_kb
if smartctl -a /dev/${drive} |grep SSD;then
#SSDs do not have latency issues like traditional hdd so we tweak
echo "/dev/${drive} is a SSD, tweaking proc entries"
@tsaavik
tsaavik / Persistent DNS Checker
Last active June 4, 2026 15:59
Persistent DNS Checker
#!/bin/bash
echo "DNS Checker v1.0 David Mcanulty 2017"
echo -e "\t- # repeatably tests dns and records success/failures\n"
success=0
failure=0
dnshost=$1
datestamp=$(date)
red=$(tput setaf 1)
green=$(tput setaf 2)
@tsaavik
tsaavik / Atomic locking for bash scripts
Last active June 4, 2026 15:59
Atomic locking for bash scripts
#!/bin/bash
lockfile=/var/lock/$(basename $0)
#Redirects output of file descriptor 5 to lockfile while this script runs
exec 5>"${lockfile}"
# flock file descriptor 5, otherwise fail
if ! flock -n 5 ; then
echo "Exiting: Another instance of $0 is already running";
exit 1
@tsaavik
tsaavik / Fix ssh sockets in Tmux and Screen,
Last active June 4, 2026 15:53
Are your long running ssh agent sockets failing? Perhaps something is cleaning /tmp? This rc file for ssh fixes all these problems.
# Fix ssh sockets in Tmux and Screen - dmcanulty 2021-2026 - https://gist.github.com/tsaavik/c0512d2d2d138a45d0db45fc4c410277
# After putting THIS file at ~/.ssh/rc add the following to your Tmux or Screen confs
# .tmux.conf - set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
# .screenrc - setenv SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock
# Now add the following to your ~/.ssh/config to prevent /tmp reapers from getting it
# Host *
# IdentityAgent ~/.ssh/ssh_auth_sock
@tsaavik
tsaavik / get-conf.sh
Created May 30, 2023 21:54
AWS CESI Script
#!/bin/bash
#
# This script grabs the Name, Ip and environment tags from aws.
# It then grabs a cesi conf header file and appends (using heredocs).
config="/opt/cesi/defaults/cesi.conf.toml"
tmpconf="/tmp/cesi.conf.toml"
# Create the header in our new copy of conf file
cp -f "${config}.head" ${tmpconf}
@tsaavik
tsaavik / gist:3f055abcb16eebcf492a
Created August 20, 2014 17:01
AWS motd tag dumper
/etc/update-motd.d/95-aws-tags
#!/bin/bash
# Print some info from the aws tags
# Color codes from http://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm/4332530#4332530
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
@tsaavik
tsaavik / kill-ipc.sh
Last active October 12, 2021 21:54
Kill all IPC semaphores. Useful when someone forgets to properly clean up. Borrowed and enhanced from a stackoverflow question.
#!/bin/bash
PATH="/bin:/usr/bin"
ipcs
read -p "press enter to kill all the ipc process owned by ${USER}"
IPCS_S=$(ipcs -s | egrep "0x[0-9a-f]+ [0-9]+" | grep ${USER} | cut -f2 -d" ")
IPCS_M=$(ipcs -m | egrep "0x[0-9a-f]+ [0-9]+" | grep ${USER} | cut -f2 -d" ")
IPCS_Q=$(ipcs -q | egrep "0x[0-9a-f]+ [0-9]+" | grep ${USER} | cut -f2 -d" ")
@tsaavik
tsaavik / .tmux.conf
Created August 16, 2021 15:21
tmux.conf
# Make things colorful
set -g default-terminal "screen-256color"
setw -g window-status-current-format '#[fg=white]#I:#{?window_zoomed_flag,#[fg=colour201]#W,#W}'
# Window title for Putty,xterm,etc
set -g set-titles on
set -g allow-rename on
# ctrl-b / sets window name to hostname -s
bind-key / send-keys "printf \"\\033k$(hostname -s)\\033\ \"" \; send-keys "Enter"
frontend stats
bind :8080
use_backend be_stats unless { path /favicon.ico }
errorfile 503 /etc/haproxy/errors/haproxy-favicon.ico
backend be_stats
stats enable
stats uri /
@tsaavik
tsaavik / sgrab
Last active October 23, 2018 20:49
Automatically grabs a screenshot of a window after a short delay (default is 2 seconds),then copies it to /Dropbox/Public/share/Screenshots/hostname/and saves path to clipboard
#!/bin/bash
# sgrab - David Mcanulty 2013
#
# Inspried by gist: https://gist.github.com/Saicheg/4231551
# Automatically grabs a screenshot of a the currently active
# window after a short delay (default is 2 seconds), and
# then copies it to /Dropbox/Public/share/Screenshots/hostname/
# and saves a tiny url encoded path to your system's clipboard
#
# You can use any scrot switch to override the defaults, like --select