Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
ThinGuy / incoming-servicetags.csv
Last active August 9, 2021 20:02
Sample file for demo
9I1P5A <hostname>.<sld>.square
XNKGGY <hostname>.<sld>.square
MDWLAT <hostname>.<sld>.square
QZPRBS <hostname>.<sld>.square
TFLJUN <hostname>.<sld>.square
0CRT1G <hostname>.<sld>.square
@ThinGuy
ThinGuy / maxcol-width.awk
Last active October 8, 2019 11:30
awk one liner: get max column width across all records
#This will print the length of the longest field in a column across all records
# awk -F"|" '{ for (i=1; i<=NF; i++) { max[i] = length($i) > max[i] ? length($i) : max[i] ;ncols = i > ncols ? i : ncols }} END { for (col=1; col <= ncols; col++) {printf "%d\n", max[col]}}'
##This example has pipe separated record adjust field separator as needed
##This example only prints the max length of each column (in order) with a CR, adjust printf statement as needed
### Sample data ####
FOO='
Host|SysID|DevID|Name|Model|Part ID|UUID|LABEL|FS|MNT|Bootable
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|48|f87c08cb-c444-4f81-af8a-5ed22947f63d|efi|fat32|/boot/efi|true
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|49|3a8024f2-0aa0-4005-8400-cf8d4a3d175d|root|ext4|/|false
@ThinGuy
ThinGuy / maxcol-length.awk
Created June 11, 2018 12:29
awk one liner: get max column lengths across all records
#This will print the length of the longest field in a column across all records
# awk -F"|" '{ for (i=1; i<=NF; i++) { max[i] = length($i) > max[i] ? length($i) : max[i] ;ncols = i > ncols ? i : ncols }} END { for (col=1; col <= ncols; col++) {printf "%d\n", max[col]}}'
##This example has pipe separated record adjust field separator as needed
##This example only prints the max length of each column (in order) with a CR, adjust printf statement as needed
### Sample data ####
FOO='
Host|SysID|DevID|Name|Model|Part ID|UUID|LABEL|FS|MNT|Bootable
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|48|f87c08cb-c444-4f81-af8a-5ed22947f63d|efi|fat32|/boot/efi|true
node01ob20|pk3fqr|73|sda|KINGSTON SV300S3|49|3a8024f2-0aa0-4005-8400-cf8d4a3d175d|root|ext4|/|false
@ThinGuy
ThinGuy / juju-missing-gpg
Last active June 16, 2018 01:18
Fix missing GPG key/fix NO PUBKEY errors while juju is deploying
juju-fix-missing-gpg-keys() {
#search juju debug log for missing GPG keys and apply them to all servers in the model
local -a MISSING_KEYS=($((juju debug-log --no-tail --replay|awk '/GPG error/{print $NF}')|sort -u))
local -a MACHINES=($(juju machines|awk '/^[0-9]+/&&/started/{print $1}'))
for k in ${MISSING_KEYS[@]};do printf "%s $k\n" ${MACHINES[@]};done|\
xargs -n2 -P0 bash -c 'juju 2>/dev/null ssh $0 sudo apt-key 2>/dev/null adv --recv-key --keyserver keyserver.ubuntu.com $1'
}
@ThinGuy
ThinGuy / maas-ready-nics.src
Last active June 18, 2018 18:45
Print relevant NIC information from Ready MaaS nodes, Useful when automating the creation of bridges, bonds, etc.
maas-ready-nic-info () {
( printf "System|ID|VLAN|Tag|MAC|Name|Child of|Parent to|Hostname|Available Subnets on current VLAN\n";
sudo -u postgres psql -P pager=off -F"|" --no-align -t maasdb -c \
"SELECT node.system_id,interface.id,interface.vlan_id,vlan.vid,interface.mac_address,interface.name,ifparent.parent_id,ifchild.child_id,node.hostname, array_to_string(array_agg(distinct subnet.cidr),',') AS niclist \
FROM maasserver_interface interface \
LEFT OUTER JOIN maasserver_vlan vlan ON vlan.id = interface.vlan_id \
LEFT OUTER JOIN maasserver_subnet subnet ON subnet.vlan_id = interface.vlan_id \
LEFT OUTER JOIN maasserver_node node ON interface.node_id = node.id \
LEFT OUTER JOIN maasserver_interfacerelationship ifparent ON interface.id = ifparent.child_id \
LEFT OUTER JOIN maasserver_interfacerelationship ifchild ON interface.id = ifchild.parent_id \
@ThinGuy
ThinGuy / showrgb-func
Last active October 6, 2018 17:29
run showrgb and show the name in the appropriate RGB color
#Updated to print full names when they include spaces and to display in columns
showrgb| \
awk '{printf "%s", "\"\\e[1;38;2;"$1";"$2";"$3"m"; for(i=4;i<=NF;i++){printf "%s ", $i};printf "\\e[0m\"\n"}'| \
xargs -L1 echo -e| \
column
@ThinGuy
ThinGuy / insert-boot-param
Last active August 15, 2018 00:52
MAAS: Insert a new boot parameter into all existing tags' kernel_opts
maas-insert-boot-param() {
local DESC="\e[1m${FUNCNAME}\e[0m: Insert a boot paramter into a specific, or all existing tags.\n"
maas-insert-boot-param_usage() {
printf "\n${DESC}\n"
printf "\e[1mUsage\e[0m: ${FUNCNAME%%_*} -p <param> [-t <tag>]\n\n"
printf "\e[1mOptions\e[0m:\n"
printf "\e[2G -p, --param \e[20GRequired: boot parameter to add\n"
printf "\e[20GEx: apparmor=0\n"
printf "\e[20GTip: Enclose multiple params in single quotes\n\n"
printf "\e[2G -t, --tag \e[20GOptional: Add only to a specific tag\n"
@ThinGuy
ThinGuy / make-chromeos-recovery.sh
Last active January 29, 2023 10:51
Create ChromeOS Recovery Media from Linux Computer
#!/bin/bash
###NOTE###
# This requires requires linux to create a ChromeOS Recovery Image.
printf "\e[2GCreate ChromeOS Recovery media using Linux machine...\n\n"
printf "\e[2G - Please ensure a (min) 4GB USB disk is plugged in, then hit ENTER.\n"
read CONT
@ThinGuy
ThinGuy / modify-chromeos-recovery-media.sh
Last active November 22, 2022 15:00
Modify ChromeOS Recovery Media to just run a script to put ChromeBook back in dev mode and enable legacy USB booting. Workaround for Issue 362105 (https://crbug.com/362105)
#!/bin/bash
###NOTE###
# This requires:
# 1) ChromeOS Recovery Media for your machine (see https://bit.ly/makechromeos-media)
# 2) A separate linux machine to alter the ChromeOS recovery media
# 99.999% of this script was lifted wholesale from http://bit.ly/2oFvluu
# This just automtes the manual parts in the guidance provided
#
@ThinGuy
ThinGuy / loc-info.sh
Created September 12, 2018 18:52
Location info via web api
curl -sSL https://timezoneapi.io/api/ip|\
jq -r 'keys[0] as $k|.[$k]|to_entries[]|select((.key != "timezone" and .key != "datetime"))|"\(.key): \(.value)"'