Skip to content

Instantly share code, notes, and snippets.

@xcorvis
xcorvis / script-template.sh
Created December 15, 2020 15:30 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@xcorvis
xcorvis / fetch-release-upgrade.sh
Last active March 5, 2025 13:37
I don't remember what I cribbed this from (stack overflow, probably) but it allows you to pre-fetch upgrade files before a do-release-upgrade. Run this in a temp dir.
#! /bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 new-release-codename"
echo "Example: $0 saucy"
exit 1
fi
NEW_CODENAME="$1"
@xcorvis
xcorvis / test_ciphers.sh
Created August 10, 2018 19:14
Tests the available openssl ciphers against a host.
#!/usr/bin/env bash
# tests openssl ciphers against a host
# source: https://superuser.com/questions/109213/how-do-i-list-the-ssl-tls-cipher-suites-a-particular-website-offers
# OpenSSL requires the port number.
SERVER=$1
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
echo Obtaining cipher list from $(openssl version).
#!/bin/bash
# clean up the current git directory a bit
# delete local branches that have been merged to master
# note that depending on your workflow, this could delete things you're still working on
( git checkout master && git pull ) || exit
( git branch -l --merged | egrep -v "\*|master|develop" | xargs git branch -D ) || exit
( git remote prune origin && git gc ) || exit
@xcorvis
xcorvis / find_old_libs
Created June 15, 2015 12:56
old libraries in use
# locate old library files that are still in use, such as after an openssl update
sudo lsof -n | grep libssl | grep DEL
# just the (truncated) names of the app using the library
sudo lsof -n | grep libssl | grep DEL | cut -c1-10 | sort | uniq
# Note that the names that services run as may also be useful for figuring out what needs to be restarted.
@xcorvis
xcorvis / add_a_param_with_sed
Created May 14, 2015 20:54
add a parameter to a line using sed
# Add a parameter to a line in a file using sed, where that parameter is missing or may already exist at any position.
# Example line:
PARAMS=quiet,splash,elevator=noop
# On the line that matches, if the entry is not present append it to the line
sed '/^PARAMS/ {/audit=1/! s/.*/\&,audit=1/}' grub.conf
# Example line:
PARAMS="quiet splash elevator=noop"
# Same as above but accounts for the trailing quote on the original string
@xcorvis
xcorvis / tail_by_timestamp
Last active January 10, 2017 19:48
show the lines of a file that that are newer than the time specified
# Two example one-liners for showing the lines of a file that that are less than x minutes old
# this is quite slow on large files
# uses older syslog date format
awk ' BEGIN { cmd="date -d \"-5 min\" +%s"; cmd | getline old; close(cmd); } { cmd="date -d \""$1" "$2" "$3"\" +%s"; cmd | getline d; close(cmd); if (d > old) print; } ' /var/log/syslog
# uses the slightly different date format
awk ' BEGIN { cmd="date -d \"-2 hour\" +%s"; cmd | getline old; close(cmd); } { cmd="date -d \""$1" "$2"\" +%s"; cmd | getline d; close(cmd); if (d > old) print; } ' /var/log/nginx/error.log
@xcorvis
xcorvis / usb-reset
Last active March 12, 2020 19:32
usb-reset script for linux
#!/bin/sh
if [ "$(id -u)" != 0 ] ; then
echo This must be run as root!
exit 1
fi
# Look for the most common cases
for driver in xhci_hcd ehci_hcd uhci_hcd ; do
# Some distros need to use these instead: xhci-pci ehci-pci uhci-pci
@xcorvis
xcorvis / convert_vmdk_to_vdi
Created July 2, 2014 19:59
convert a vmware vmdk to a virtualbox vmi in Linux
Install virtualbox and qemu
qemu-img convert image.vmdk image_2.vmdk image.bin
VBoxManage convertdd image.bin image.vdi