Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Usage:
# 0 * * * * /home/zerolagtime/bin/do_backup.sh -t hourly -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -k Documents # JOB_ID_1
# 0 0 * * * /home/zerolagtime/bin/do_backup.sh -t daily -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -k Documents # JOB_ID_2
# 0 0 * * 1 /home/zerolagtime/bin/do_backup.sh -t monthly -s /home/zerolagtime/Documents -d /data/backups/zerolagtime/Documents/ -l /home/zerolagtime/backups-documents.log -K Documents # JOB_ID_3
VERSION="2.2"
DEBUG=0
LOGFILE=""
KEYWORD=""
@zerolagtime
zerolagtime / output-noisy-failure.txt
Created September 23, 2021 01:35
Bash skeleton - supports colored output for WARN and ERROR
$ ./script-template.sh --noisy
[[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] command -v /tmp/script-template.sh
[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] dirname /tmp/script-template.sh
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:200] cd /tmp
[[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:201] pwd
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:201] here=/tmp
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:202] log_debug 'Starting main function of /tmp/script-template.sh'
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:159] main(): :
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:203] main
[Wed 22 Sep 2021 09:32:21 PM EDT][/tmp/script-template.sh:24] main(): log_info 'our informational message'
@zerolagtime
zerolagtime / script-template.sh
Last active March 19, 2021 13:52
BASH Shell Script Skeleton Template
#!/bin/bash
# This is a template script that has built-in logging
# with colored messages. It also supports command line parsing.
usage() {
echo "$0 [-h | --help] [-v | --verbose]"
echo " [-q | --quiet] [-w str | --with-parameter=str]"
echo " [--noisy]"
echo "Here is the reason this script exists."
echo "Where:"
@zerolagtime
zerolagtime / internal_envsubst.sh
Created June 1, 2020 20:01
envsubst in pure bash/sed
#!/bin/bash
# this is a poor man's substitute for the envsubst command
function internal_envsubst() {
tfile=$(mktemp)
# use sed to build a sed input file specific to the current environment variables
env | sed -E -e '
# delete any special cases that make a mess of things
/^_=/d;
# deal with variables that have backslashes in them: \\tsclient\home
@zerolagtime
zerolagtime / k3b_to_playlist.py
Created August 28, 2015 04:04
Convert K3B audio projects into M4A files suitable for use on Apple devices that cannot handle numerous audio file formats.
#!/usr/bin/env python3
# Copyright 2015 by Charlie Todd except where noted below.
# You are granted permission to adapt this gist for your own project,
# but not to claim the work as entirely your own. Attribution must
# be provided in any derivative works in such a fashion that the
# final user of the software can see and understand the attribution.
import sys
import zipfile
import xml
import xml.dom.minidom