Skip to content

Instantly share code, notes, and snippets.

@adamzwakk
adamzwakk / pgsqlvacuumstat.sh
Created July 27, 2022 20:35
Gets running postgresql vacuums and phases ready for influxdb
#!/bin/bash
PGSQL_HOST="localhost"
PGSQL_PORT="5432"
PGSQL_DATABASE="postgres"
PGSQL_USERNAME="postgres"
export PGPASSWORD="passwd"
TMP_FILE="/tmp/pgsqlchk.out"
ERR_FILE="/tmp/pgsqlchk.err"
HOST=$(hostname)
@adamzwakk
adamzwakk / pg_recovery_progress.sh
Last active July 15, 2022 10:05
Looks up where postgres startup recovery is at in the WAL files
ls -l $(sudo lsof -p $(ps aux | grep postgres | grep startup | awk '{print $2}') | grep wal | awk '{print $9}') | awk '{print $6" "$7" "$8}'
@adamzwakk
adamzwakk / slackpost.sh
Last active July 4, 2022 18:08
Slack Helper to send stdout or messages from bash/shell to Slack message API quickly
#!/bin/bash
## Defaults
SLACK_TOKEN="YOUR TOKEN"
CHANNEL="YOUR CHANNEL"
IN=""
MESS=""
while getopts c:m: flag
do
@adamzwakk
adamzwakk / get_blocking_queries.sh
Last active February 14, 2022 21:32
Get potentially blocking queries from postgresql log, cross ref with stat_activity and post to slack
#!/bin/bash
PGSQL_HOST="localhost"
PGSQL_PORT="5432"
PGSQL_DATABASE="postgres"
PGSQL_USERNAME="postgres"
export PGPASSWORD="passwd"
xmins=()
queries=""
@adamzwakk
adamzwakk / nb_get.py
Created February 10, 2022 15:21
Get active Jupyter Notebook sessions, combine with ps to get ram/cpu usage and prep for InfluxDB
import requests
import json
s = requests.Session()
resp = s.get('{notebook URL}/login', verify = False)
xsrf_cookie = resp.cookies['_xsrf']
params = {'_xsrf':xsrf_cookie,'password': '{notebook password}'}
l = s.post('{notebook URL}/login?next=/api/sessions', data=params, verify = False, allow_redirects=True).json()
@adamzwakk
adamzwakk / psqlactiveq.sh
Created February 8, 2022 15:27
Get active queries from postgres and send them to influxdb (or comment out curl and echo the lines to be used with telegraf)
#!/bin/bash
PGSQL_HOST="localhost"
PGSQL_PORT="5432"
PGSQL_DATABASE="postgres"
PGSQL_USERNAME="postgres"
export PGPASSWORD="passwd"
THISHOST=`hostname`
INFLUXLINES=""
@adamzwakk
adamzwakk / UT2004SetupPublicDLs.sh
Last active June 13, 2021 00:46
Moves any UT2004 files to www folder for redirect hosting (tries to skip vanilla files)
compress_ut_file() {
f=$(basename $1)
if [ ! -d "$file" -a ! -f "/var/www/ut2004/${f}.uz2" ] && [ "$file" != "*" ]; then
./ucc-bin compress -nohomedir $1
mv "${1}.uz2" /var/www/ut2004/
fi
}
export -f compress_ut_file
@adamzwakk
adamzwakk / generate-map.js
Created September 9, 2019 18:00
Node.JS script to generate map tiles from a source image for leaflet.js
// node .\tools\generate-map.js --bigfile .\src\fullmap.jpg --endpath .\public\grid\ --zoom 7
const fs = require('fs');
const sharp = require('sharp');
const argv = require('yargs').argv;
const _cliProgress = require('cli-progress');
const endPresentFile = argv.bigfile;
const gridPath = argv.endpath;
const bar1 = new _cliProgress.SingleBar({}, _cliProgress.Presets.shades_classic);
@adamzwakk
adamzwakk / backlight.sh
Created October 30, 2018 03:26
control laptop backlight via xbacklight and send notification via libnotify
#!/bin/bash
# You can call this script like this:
# $./backlight.sh up
# $./backlight.sh down
function get_brightness {
cat /sys/class/backlight/intel_backlight/brightness;
}
@adamzwakk
adamzwakk / volume.sh
Last active October 30, 2018 02:47 — forked from sebastiencs/volume.sh
Script to get volume notification with dunst http://imgur.com/a/qWgAw
#!/bin/bash
# You can call this script like this:
# $./volume.sh up
# $./volume.sh down
# $./volume.sh mute
function get_volume {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}