Skip to content

Instantly share code, notes, and snippets.

@AndrewPaglusch
AndrewPaglusch / docker_get_physical_interfaces.sh
Last active October 8, 2021 23:53
Find the Host "veth" Interface Each Running Docker Container is Using
# This script will tell you what Docker container is tied to which vethXXXXXXXX interface on the host
# All other "solutions" to this problem that I found require you to exec into the container
#!/bin/bash
{ echo -e "CONTAINER_NAME\tPID\tINTERFACE"
docker ps --format '{{.Names}}' | while read cname; do
PID="$(docker inspect --format="{{.State.Pid}}" "${cname}")"
INTERFACE="$(ip link show | grep -P "^$(nsenter -t "${PID}" -n ip link show eth0 | grep -oP '(?<=@if)[^:]+')(?=:)" | grep -oP 'veth[^@]+')"
echo -e "${cname}\t${PID}\t${INTERFACE}"
done } | column -t
@AndrewPaglusch
AndrewPaglusch / d_stuck.sh
Created July 7, 2021 19:05
Detect Processes in "D" State & Reboot via SysRq After Sending Matrix Alert
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
function matrixMessage {
local INPUTMSG=$1
local MATRIX_SERVERURL="matrix.server.com" #dont add http(s)
local MATRIX_ROOMID="!xXxXxXxXxXxX" #Format: !XxXxXxXxXxXxXx
local MATRIX_TXNID="$(date +%s)"
@AndrewPaglusch
AndrewPaglusch / elkarbackup_health.sh
Last active April 9, 2022 01:52
Get Elkarbackup Clients that Haven't Had a Successful Backup Job Within the Last 72 hours - Send Matrix Alert
#!/usr/bin/env bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
function matrixMessage {
local INPUTMSG=$1
local MATRIX_SERVERURL="matrix.server.com" #dont add http(s)
local MATRIX_ROOMID="!xXxXxXxXxXxX" #Format: !XxXxXxXxXxXxXx
local MATRIX_TXNID="$(date +%s)"
@AndrewPaglusch
AndrewPaglusch / install_prometheus_and_node_exporter.md
Last active September 5, 2021 00:25
Prometheus (in Docker) and node_exporter Install & Configure

Prometheus Server (in Docker)

$ mkdir /opt/docker && cd /opt/docker
$ cat > docker-compose.yml <<'EOF'
version: '3.3'
services:
  prometheus:
    image: prom/prometheus
 container_name: prometheus
@AndrewPaglusch
AndrewPaglusch / github_repo_download.sh
Last active April 25, 2022 14:09
Download All Public GitHub Repos for User
github_username='YourUsernameHere'
github_pat='YourGitHubPATHere'
curl -s -u "${github_username}:${github_pat}" 'https://api.github.com/user/repos?per_page=100' | grep -oP '(?<=clone_url\":[ ]\")[^(\",)]+' | sed "s|https://|https://${github_username}:${github_pat}@|" | while read repo; do
reponame=$(grep -oP '(?<=\/)[^\/]+$' <<< $repo | sed 's/.git//')
if [ -d $reponame ]; then
echo "$reponame exists. Pulling latest changes..."
cd "$reponame"
git reset --hard
git pull --ff-only
cd -
@AndrewPaglusch
AndrewPaglusch / github_gists_export.sh
Created May 2, 2021 01:12
Export All GitHub Gists for a User - One Liner
curl -s 'https://api.github.com/users/AndrewPaglusch/gists' | grep -oP '(?<=raw_url\":[ ]\")[^(\",)]+' | while read i; do filename=$(grep -oP '(?<=\/)[^\/]+$' <<< $i); echo "Downloading $filename..."; curl -Lso "$filename" "$i"; done
@AndrewPaglusch
AndrewPaglusch / matrix_notify.rb
Created May 1, 2021 07:08
matrix_notify (Ruby)
#!/usr/bin/env ruby
require 'net/http'
require 'openssl'
require 'json'
def send_matrix(server, room_id, api_key, message)
uri = URI("https://#{server}/_matrix/client/r0/rooms/#{room_id}:#{server}/send/m.room.message/#{Time.now.to_i}?access_token=#{api_key}")
req = Net::HTTP::Put.new(uri)
req.body = {"msgtype" => "m.text", "body" => message}.to_json
req['Content-Type'] = 'application/json'
@AndrewPaglusch
AndrewPaglusch / sync_check.sh
Last active May 2, 2021 00:00
Syncoid Sync Check
#!/bin/bash
##################################################################################
# MIT License #
# #
# Copyright (c) 2021 Andrew Paglusch #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
@AndrewPaglusch
AndrewPaglusch / cloudflare_backup.sh
Created February 7, 2021 19:14
Backup Up All Cloudflare Zones to Disk
#!/usr/bin/bash
export CF_API_KEY='xXxXxXxXxXxXxXxXxXxXxXxX'
export CF_API_EMAIL='user@domain.com'
curl -sX GET "https://api.cloudflare.com/client/v4/zones" -H "X-Auth-Email: ${CF_API_EMAIL}" -H "X-Auth-Key: ${CF_API_KEY}" -H "Content-Type: application/json" | grep -oP '(?<=","name":")[^"]+(?=","status":")' | while read i; do
echo "Backing up zone \"${i}\"..."
docker run --rm -e CF_API_KEY="$CF_API_KEY" -e CF_API_EMAIL="$CF_API_EMAIL" lfaoro/flares "${i}" > ./"${i}.zone"
done
echo "Done"
@AndrewPaglusch
AndrewPaglusch / restic_backup_elkar.sh
Created February 7, 2021 01:12
Restic Backup to B2 for Elkarbackup
#!/bin/sh
##################################################################################
# MIT License #
# #
# Copyright (c) 2021 Andrew Paglusch #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #