Skip to content

Instantly share code, notes, and snippets.

@GitarPlayer
GitarPlayer / content_library_import.py
Last active March 18, 2024 12:42
Import item via https to content library with vSphere SDK
import argparse
from com.vmware.content.library_client import Item
from com.vmware.content.library.item_client import UpdateSession
from com.vmware.vapi.std_client import DynamicID
from vmware.vapi.vsphere.client import create_vsphere_client
import requests
import ssl
def main():
parser = argparse.ArgumentParser(description='vSphere automation script.')
@GitarPlayer
GitarPlayer / variables.sh
Created August 8, 2023 19:20
Chapter 1 script components
#!/bin/bash
# define var in script
GREETING="Welcome"
echo GREETING
echo $GREETING
# pass var as arg
echo "you have typed $1 as the first argument"
echo "these are all arguments: $@"

Creates an example ansible-navigator.yml config:

ansible-navigator settings --sample > ansible-navigator.yml
set ts=2 sw=2 sts=2
set et
set nu ru
set ai si
set hlsearch
syntax on
filetype plugin indent on

To look through all man pages for a string there are two options

  1. loop through the manpages files with find, xargs and zgrep:
find $(manpath|tr ':' ' ') -type f -print0 | xargs -0 zgrep -i '\.config/systemd'
  1. simply use man -K notice the capital K:
man -K '.config/systemd'

Sorting cmd output by column with the sort command

Some commands come with their own sorting functionality. Anyhow it's an useful flag to have in your repertoire

So let's say we want to sort by VSZ and we have this output.

[azureuser@alma ~]$ ps aux |head -5
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  1.5  0.1 175056 13480 ?        Ss   19:24   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 16
root           2  0.0  0.0      0     0 ?        S    19:24   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   19:24   0:00 [rcu_gp]
@GitarPlayer
GitarPlayer / tr.md
Created March 31, 2022 07:13
replace all newlines with a space with tr and -s squeeze option
string_with_newlines='a
b
c'
echo $string_with_newlines |tr -s '\n' ' '
a b c
@GitarPlayer
GitarPlayer / cert.md
Created March 4, 2022 08:57
verify tls key and cert match
openssl x509 -noout -modulus -in server.crt| openssl md5
openssl rsa -noout -modulus -in server.key| openssl md5
# really cool feature of openssl
openssl s_server -cert server.crt -key server.key
# if the keys don't match you will get an error message
@GitarPlayer
GitarPlayer / grep.md
Last active March 4, 2022 08:51
grep that compares two configs a and b and finds all config lines present in file a and not in b. Of course a diff could do that, but sometimes you don't want to deal with the order or the differences of whitespaces. between the configs.
cat a
a
b
c
d
e
cat b
c
d