Skip to content

Instantly share code, notes, and snippets.

View ob1-sc's full-sized avatar

Simon O'Brien ob1-sc

  • VMware
  • United Kingdom
View GitHub Profile
@ob1-sc
ob1-sc / aws-ssm-login
Created March 25, 2019 17:42
Access managed ec2 instance via SSM
JUMPBOX_NAME="<name of ec2 instance>"
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=$JUMPBOX_NAME" \
--output text --query 'Reservations[*].Instances[*].InstanceId')
aws ssm start-session --target "$INSTANCE_ID"
@ob1-sc
ob1-sc / lastpass-cli-how-to.md
Last active April 14, 2022 15:33
How to setup and use LastPass cli to retrieve secrets when scripting

Prerequisties

  1. An active LastPass account
  2. LastPass cli installed, see here

Create a password entry in LastPass with the following details:

  • name: my-super-secret
  • username: my-super-secret-username
  • password: my-super-secret-password
@ob1-sc
ob1-sc / om-upload-tile
Created October 12, 2018 13:50
Upload Tile to Ops Manager using om cli
export FILE_NAME="cf-2.2.7-build.8.pivotal" # This is the name of the file (tile) to upload to om
export OM_USER="admin"
export OM_PWD="supersecurepassword"
export OM_TARGET="ops-manager address"
export OM_TIMEOUT=86400 # set a high timeout incase upload takes a while
om -t $OM_TARGET -u $OM_USER -p $OM_PWD -k upload-product -p $FILE_NAME -r $OM_TIMEOUT
@ob1-sc
ob1-sc / pivnet-download-tile
Last active October 18, 2018 14:01
Simple Script to download tile from pivnet
export PIVNET_TOKEN="123456" # Get from network.pivotal.io
export DEPLOYMENT_URL="http://network.pivotal.io" # This is the API download URL for your release
export FILE_NAME="ert.zip" # This is the name of the file that gets created locally
# download from pivnet
wget -O "$FILE_NAME" --post-data="" --header="Authorization: Token $PIVNET_TOKEN" "$DEPLOYMENT_URL"
# download from pivnet (with special sauce for flaky connections)
wget -c --tries=0 --retry-connrefused --timeout=2 --wait=1 -O "$FILE_NAME" --post-data="" --header="Authorization: Token $PIVNET_TOKEN" "$DEPLOYMENT_URL"
@ob1-sc
ob1-sc / ubuntuu-codename-mint
Created October 1, 2018 11:12
Get underlying Ubuntu codename (ie xenial/bionic/etc) in mint
source /etc/os-release
echo $UBUNTU_CODENAME # xenial
@ob1-sc
ob1-sc / syslog-file-fix
Created September 20, 2018 14:26
Fix syslog
cd /var/log
touch syslog
chown syslog:adm syslog
service rsyslog restart
logger "Didier MISSON logger test"
@ob1-sc
ob1-sc / gorouter-routes
Created September 5, 2018 09:45
List gorouter routes
# 1) ssh into gorouter
# 2) get router_status credentials from /var/vcap/jobs/gorouter/config/gorouter.yml or from bosh manifest router job
# 3) get routes
curl "http://router_status:<router_status password>@127.0.0.1:8080/routes" | python -m json.tool
@ob1-sc
ob1-sc / sudo-sshpass-remote
Created September 4, 2018 10:53
Run script on remote server as sudo
#!/bin/bash
SUDO_PWD=superSecurePassword
ROOT_USER=root
SERVER=10.0.0.097879879
SCRIPT_TO_RUN=script_to_run.sh
SUDO_ECHO_SCRIPT=sudo_echo.sh
# generate script to run on remote server
@ob1-sc
ob1-sc / flatten_tile_plan_properties
Created July 17, 2018 15:14
Flatten tile plan properties
[to_entries[] | {(.key) : .value.value}] | reduce .[] as $item ({}; . + $item)
@ob1-sc
ob1-sc / tile_plan_extraction
Created July 17, 2018 15:12
Extract named plan from tile properties
PLANS_PROPERTY=".properties.rds_postgres_plans"
PLAN_NAME=".properties.rds_postgres_plans"
jq --arg plans_property "$PLANS_PROPERTY" --arg plan_name "$PLAN_NAME" '.properties | to_entries[] | select(.key == $plans_property) | .value.value[] | select(.name.value == $plan_name)'