Skip to content

Instantly share code, notes, and snippets.

@tsaavik
tsaavik / mp3-tuner.sh
Last active October 12, 2021 21:56
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 sda sdb sdc sdd; 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 / 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
@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 / Puppet Parser and Lint git pre-commit hook script
Created January 2, 2014 23:05
Puppet parser/lint git pre-commit hook script. Improves on versions I've seen around the net
#!/bin/bash
declare -a files
IFS=$'\n'
# Check for puppet lint
if requires=$(which puppet puppet-lint git 2>&1) ;then
: #We have puppet-lint and git, good
else
echo -e "Error, missing required item(s) from path.\n Requires: git puppet-lint\n\nFound:\n${requires}"
exit 1
@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 / gist:6c8134a8c026eaea0f45
Created January 8, 2015 17:06
diff: add restart-sidekiq to gitlab
#! /bin/bash
# GITLAB
# Maintainer: @randx
# App Version: 6.0
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
@tsaavik
tsaavik / rsyncr
Last active January 21, 2016 18:38
Automatic rsync retry with incremental (delay) backoff
#!/bin/bash
#
# Rsyncr (Rsync Retry) 2016 David Mcanulty
# Runs rsync, retrying on errors up to a maximum number of tries with incremental backoff (delay)
# Based on idea from https://gist.github.com/iangreenleaf/279849 by iangreenleaf 2011
# Set your max rsync retries here
max_retries=50
# Trap interrupts (ctrl-c) and exit instead of continuing the loop
# This restarts the agent every 30 days, to make sure its not hung
# And also checks that the lockfile isn't more then 1 hour old
check process puppet with pidfile /var/run/puppet/agent.pid
group system
start program = "/usr/sbin/service puppet start"
stop program = "/usr/sbin/service puppet stop"
if 5 restarts within 5 cycles then timeout
if uptime > 30 days then restart
@tsaavik
tsaavik / gist:c176aa97eeee7bac2502ba2b9e01f2a4
Last active July 18, 2016 15:38
Auto start xen instance confs based on images present
#!/bin/bash
# Auto start xen instance confs based on images present
cd /home/dave/xen/images/
for xenimage in *.img ;do
xm create ${xenimage%%\.*}
sleep 30
done
@tsaavik
tsaavik / oldprocesskiller.sh
Created August 9, 2016 16:25
Old Process Killer - Finds the passed process name that has been running longer than 24 hours and kills it
#!/bin/bash
# Check for user input
process=$@
if [[ -z "${process}" ]] ;then
echo "This program requires a process name."
echo "The (oldest) given process name will be killed"
echo "if it has been running for > 24 hours"
exit 1
fi