Skip to content

Instantly share code, notes, and snippets.

@jrh-spg
jrh-spg / diskclone.sh
Last active November 17, 2021 03:52
Disk Cloner Script that uses dd to clone disks
#!/bin/bash
# https://asciinema.org/a/6LZefsbvLjgsuwQHOnQsBEaSj
IF=notset
OF=notset
BS=128M
CURDIR=$(dirname $(realpath -s $0))
SCRIPT=`basename "$0"`
if [[ ! -f /usr/bin/pv ]]; then
echo "pv is not installed. Please install pv and try again"
@jrh-spg
jrh-spg / icywatch.sh
Last active June 4, 2021 15:03
Icecast connection watcher
#!/bin/bash
TERM=xterm-256color
bold=$(printf '\033[1m')
lred=$(printf '\033[91m')
lblue=$(printf '\033[94m')
white=$(printf '\033[97m')
green=$(printf '\033[92m')
lgreen=$(printf '\033[36m')
yellow=$(printf '\033[33m')
@jrh-spg
jrh-spg / sinkselector.sh
Last active December 22, 2019 18:50
Pulse Audio Sink Selector
#!/bin/bash
tempfile=$(tempfile 2>/dev/null) || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
INPUT=$(mktemp)
function get_all_sinks() {
pacmd list-sinks | grep -e 'name:' | cut -d: -f2 | cut -d\< -f2 | cut -d\> -f1
}
#!/bin/bash
options=':i:s:d:n:p:h:'
while getopts ${options} option
do
case ${option} in
i) interval=$OPTARG;;
s) site=$OPTARG;;
d) domain=$OPTARG;;
n) nameservers=$OPTARG;;
@jrh-spg
jrh-spg / backup.sh
Last active March 11, 2019 21:07
A simple duplicity backup script
#!/bin/bash
ulimit -n 10000
PIDFILE=/var/run/backup.pid
LOGFILE=/var/log/backup.log
if [ -f "$PIDFILE" ]; then
RUNPID=`cat $PIDFILE`
if ps -p $RUNPID; then
echo "Backups are already running..."
exit 1
while [ "$hn" == "" ]; do
clear
read -p "Hostname: " hn
done
clear
echo "network --device eth0 --bootproto=dhcp --hostname ${hn}" > /tmp/network.ks
pw=""
while [ "$pw" == "" ]; do
function imgup
chmod 644 $argv
rsync -paqe ssh $argv mountain:~/images
for i in $argv
echo "http://images.cookietronics.net/$i"
end
end
#!/bin/bash
# Create the lock file to prevent parallel instances.
LOCKFILE=/tmp/.backup.sh.lck
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "already running"
exit
fi
# make sure the lockfile is removed when we exit and then claim it
@jrh-spg
jrh-spg / web_backup.sh
Last active January 9, 2016 19:18
Backup script to backup my document root and MySQL databases to a remote backup server.
#!/bin/bash
LOCKFILE=/tmp/.wb.lck
HOST=web01.fisys.us
BACKUPHOST=25.23.239.150
DOCROOT=/var/www
EXCLUDEDB='schema\|mysql'
EXCLUDE=.git
DATE=`date +%Y-%m-%d.%H%M`
BACKUPDIR=/mnt/backup
BACKUPFILE=$BACKUPDIR/$HOST.backup-$DATE.tar.bz2
@jrh-spg
jrh-spg / ipcheck.sh
Created October 26, 2013 20:05
Script to email you if your home IP changes.
#!/bin/bash
IP=`cat /tmp/ip`
PUBIP=`curl -s http://icanhazip.com`
EMAIL=youremail@domain.com
if [ "$IP" != "$PUBIP" ]; then
echo $PUBIP|mail -s "IP changed at home" $EMAIL
echo $PUBIP > /tmp/ip
fi