Skip to content

Instantly share code, notes, and snippets.

View mstarks01's full-sized avatar

Michael Starks mstarks01

View GitHub Profile
<a rel="me" href="https://noc.social/@libr8r">Mastodon</a>
#!/bin/bash
# Exit if any variables are unset. May need to be uncommented if trying to expand positional parameters.
set -u
# Try to catch errors, but beware that some non-zero conditions are OK
set -e
# Capture errors within a pipeline
set -o pipefail
# From: https://google.github.io/styleguide/shellguide.html
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
if ! do_something; then
err "Unable to do_something"
exit 1
fi
@mstarks01
mstarks01 / trap_ctrl_c.sh
Last active March 7, 2022 00:59
Trap Ctrl-C in Bash
# Credit: https://www.loggly.com/install/configure-linux.sh
#trapping Control + C
#these statements must be the first statements in the script to trap the CTRL C event
trap ctrl_c INT
function ctrl_c() {
# Do something here
exit 1
#!/usr/bin/env bash
profile=network-throughput
# Usage: die message ...
die() {
printf '%s\n' "$*" >&2
exit 1
}
@mstarks01
mstarks01 / relabel_selinux.txt
Last active November 24, 2021 01:28
Relabel SELinux
From: https://access.redhat.com/solutions/24845
set SELINUX=permissive in /etc/selinux/config
Run fixfiles onboot or touch /.autorelabel
reboot
check the /var/log/messages and /var/log/audit/audit.log for new SELinux messages
set SELINUX=enforcing in /etc/selinux/config
Run fixfiles onboot or touch /.autorelabel
reboot
@mstarks01
mstarks01 / bind_mount_in_chroot.txt
Last active November 24, 2021 01:29
Bind Mount in Chroot
cd /mnt/foo
mount -t proc /proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/

The netfilter hooks in the kernel and where they hook in the packet flow

The figure below calls out

  • The netfilter hooks
  • The order of table traversal
@mstarks01
mstarks01 / log_all_commands.txt
Last active November 24, 2021 01:35
Command Logging in Linux
Source: Matt Springfield. Original source unknown.
In /etc/bashrc (or profile):
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
For rsyslog: in /etc/rsyslog.d/bash.conf:
Local6.* /var/log/commands.log (or wherever you want to send the data)
@mstarks01
mstarks01 / escaping_json.txt
Last active November 24, 2021 01:32
Characters that must be escaped in JSON strings
Source: https://www.sitepoint.com/basics-json-syntax-tips/
quotation mark “
forward slash /
back slash \
new line n
carriage return r
tab t