Skip to content

Instantly share code, notes, and snippets.

hostnamectl set-hostname NEW_NAME_HERE
@gregjhogan
gregjhogan / eth-negotiated-speed.sh
Created October 16, 2018 00:05
check ethernet negotiated speed
sudo ethtool eth0 | grep Speed
@gregjhogan
gregjhogan / pip-downgrade.sh
Created October 18, 2018 22:00
downgrade pip to a specific version
sudo python -m pip install pip==18.0 --upgrade
@gregjhogan
gregjhogan / git-convert-to-shallow.sh
Created October 19, 2018 01:15
convert git repo to shallow clone
git pull --depth=1
git gc --prune=all
@gregjhogan
gregjhogan / azure-vm-extract-tag-value.sh
Last active October 29, 2018 21:34
Azure VM extract tag value
$TAG_NAME=???
curl -s -H 'Metadata:true' 'http://169.254.169.254/metadata/instance?api-version=2017-08-01' | jq '.compute.tags' | sed -e 's/"/;/g' | sed -e "s/.*;${TAG_NAME}:\(.*\);.*/\1/"
@gregjhogan
gregjhogan / docker-cloudstor-azure-file-share-volume.sh
Created October 31, 2018 20:11
docker cloudstor azure file share volume
# ONLY WORKS FROM INSIDE AZURE !!! (cloudstor can't mount CIFS v3 volumes - required when connecting over internet)
STORAGE_ACCOUNT=<account>
STORAGE_KEY=<key>
STORAGE_SHARE=<share>
# configure
docker plugin install --alias cloudstor:${STORAGE_ACCOUNT} --grant-all-permissions docker4x/cloudstor:18.06.1-ce-azure2 CLOUD_PLATFORM=AZURE AZURE_STORAGE_ACCOUNT_KEY="${STORAGE_KEY}" AZURE_STORAGE_ACCOUNT="${STORAGE_ACCOUNT}" AZURE_STORAGE_ENDPOINT="core.windows.net" DEBUG=1
# create
docker volume create --driver=cloudstor:${STORAGE_ACCOUNT} --opt=share=${STORAGE_SHARE} ${STORAGE_SHARE}
# test
docker run --rm -v ${STORAGE_SHARE}:/data --cap-add SYS_ADMIN --cap-add DAC_READ_SEARCH -it busybox
@gregjhogan
gregjhogan / ssh-tar-backup-restore.sh
Created November 7, 2018 23:11
tar backup/restore over SSH
# preserves source directory structure on target
tar cf - /<path>/<to>/<dir> | ssh <target-server> tar xf -
# preserves source directory structure on target
sudo xfsdump -l0 -s <relative>/<path> - /<device> | ssh <target-server> xfsrestore - /<device>
@gregjhogan
gregjhogan / rsync-copy-mirror-directory.sh
Last active February 13, 2019 06:55
rsync directory mirror copy
rsync -aHAXz --checksum --partial --delete --progress /<path>/<to>/<dir> <target-server>:/<path>/<to>/<dir>/
@gregjhogan
gregjhogan / azure-sdk-python-key-vault-get-secret-using-client-from-cli-credentials.py
Created November 29, 2018 01:04
azure sdk python key vault get secret using client from cli credentials
from azure.common.credentials import get_azure_cli_credentials
credentials, subscription_id = get_azure_cli_credentials(resource="https://vault.azure.net")
kv_client = KeyVaultClient(credentials=credentials)
kv_secret = kv_client.get_secret("https://<vault-name>.vault.azure.net/", "<secret-name>", "")
print(kv_secret.value)