Skip to content

Instantly share code, notes, and snippets.

@karlskewes
karlskewes / awk_netstat.sh
Created March 14, 2023 21:04 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@karlskewes
karlskewes / cfs.yaml
Created October 20, 2020 01:28
CPU quota period (CFS) Kubernetes Manifest
# This gist built into container and run on Kubernetes
# https://gist.github.com/bobrik/2030ff040fad360327a5fab7a09c4ff1
---
apiVersion: v1
kind: Namespace
metadata:
name: cfs
labels:
name: cfs
app.kubernetes.io/name: cfs
@karlskewes
karlskewes / delete-dockerhub-images.sh
Last active November 13, 2018 20:40 — forked from jriguera/delete-dockerhub-images.sh
Delete Docker images on DockerHub
#!/bin/bash
# TODO: Tidy up! - Karl
# Based on kizbitz/dockerhub-v2-api-organization.sh at https://gist.github.com/kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721
# Example for the Docker Hub V2 API
# Returns all images and tags associated with a Docker Hub organization account.
# Requires 'jq': https://stedolan.github.io/jq/
# set username, password, and organization
@karlskewes
karlskewes / genkeys.sh
Created September 27, 2018 03:40 — forked from jhamrick/genkeys.sh
Generate SSL certificates with IP SAN
#!/usr/bin/env bash
#
# Generate a set of TLS credentials that can be used to run development mode.
#
# Based on script by Ash Wilson (@smashwilson)
# https://github.com/cloudpipe/cloudpipe/pull/45/files#diff-15
#
# usage: sh ./genkeys.sh NAME HOSTNAME IP
set -o errexit
@karlskewes
karlskewes / boxstarter.ps1
Last active August 12, 2018 10:46 — forked from jessfraz/boxstarter.ps1
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Current Author: Karl
#
# Forked from: Jess Frazelle <jess@linux.com>
# Whom Last Updated: 2017-09-11 (and did all of the work).
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
@karlskewes
karlskewes / logger.ps1
Last active April 23, 2021 10:22 — forked from barsv/logger.ps1
Logging in powershell with log rotation
# Logging settings
# $logFile = "c:\temp\log-$(gc env:computername).log"
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line