Skip to content

Instantly share code, notes, and snippets.

View xbalaji's full-sized avatar

Balaji (xbalaji) V xbalaji

View GitHub Profile
@xbalaji
xbalaji / oneliners-aws-resources.sh
Last active August 3, 2022 09:56
aws list resources
# list all regions
aws ec2 describe-regions --output text | cut -f3-
# the use resourcegrouptaggingapi to list resources in each region
aws resourcegroupstaggingapi get-resources --region ${REG_NAME} | jq -r '.[][] | .ResourceARN'
aws resourcegroupstaggingapi get-resources --tag-filters "Key=XYZ" | jq -r '.[][] | .ResourceARN as $res | .Tags[] | select(.Key == "XYZ") | [$res, .Value ] | @csv '
# display all non-us regions
aws ec2 describe-regions | jq -r '.Regions[] | select(.RegionName | test("^(?!(us-).*)")) | .RegionName'
@xbalaji
xbalaji / oneliners-aws-iam.sh
Last active February 24, 2021 04:23
aws iam one liners
aws iam list-users | jq '.Users[].UserName' | xargs -t -L 1 -I {} aws iam list-user-tags --user-name {} | jq '.Tags'
@xbalaji
xbalaji / oneliners-json2yml.sh
Last active October 10, 2022 04:03
json2yml one liner
# oneliners-json2yml.sh
cat "json-file" | python -c 'import sys,yaml; yaml.dump(yaml.safe_load(sys.stdin),sys.stdout)'
python -c 'import sys,yaml; yaml.dump(yaml.safe_load(sys.stdin),sys.stdout)' < "json-file"
@xbalaji
xbalaji / walk_aws_cli.sh
Last active September 17, 2019 03:12
aws cli shell script handling next token
walk_aws_cli()
{
ToCombine="$1"
shift
AwsCliCmd="$@"
DirName="${FUNCNAME[0]}-$$"
mkdir $DirName
LoopCount=0
@xbalaji
xbalaji / github-download-file.sh
Last active October 10, 2022 04:05
download a single github file
# github-download-file.sh
github_download_file()
{
fileurl=$(echo ${2} | sed -e 's,github.com,api.github.com/repos,;s,blob/master,contents,')
curl -sqk -H "Authorization: token ${1}" -H "Accept: application/vnd.github.v3.raw" -O -L "${fileurl}"
}
# call like: github_download_file $MY_TOKEN "https://github.com/xbalaji/xbenv/blob/master/gvimrc.html"
@xbalaji
xbalaji / mount-help.sh
Last active June 27, 2020 03:05
mount-cdrom-vmplayershared-remotehost-directories
# mount ubuntu cdrom -
sudo mount /dev/sr0 /mnt/cdrom
sudo mount /dev/cdrom /mnt/cdrom # older systems
# mount vmplayer shared directory
sudo mkdir -p /mnt/hgfs
sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
# mount remote machine windows or samba share
sudo mkdir -p $HOME/remote
@xbalaji
xbalaji / gist-get-public-gists.sh
Last active October 21, 2023 17:17
gist-access-download-bookmark
#! /usr/bin/env bash
function get_public_gists()
{
for uid in ${@}
do
curl -sk -o - "https://api.github.com/users/${uid}/gists?per_page=200" | jq -r --arg dx $uid '.[].files[]| "-sk --create-dirs -o \($dx)/\(.filename) \(.raw_url)"' | xargs -t -L 1 curl
done
}
get_public_gists xbalaji xbalajipge
@xbalaji
xbalaji / gen_aws_account_no.py
Last active July 20, 2019 20:46
generate aws account numbers
import random
for ix in range(10):
print('"{}"'.format("".join([str(random.randrange(10)) for ix in range(12)])))
# execute this program like:
# wget -q -O - "https://gist.githubusercontent.com/xbalaji/26f0e8ec95ab6259a70b1762f33da948/raw/gen_aws_account_no.py" | python -
@xbalaji
xbalaji / aws_cdk_install.sh
Last active May 16, 2019 05:59
aws-cdk-notes
sudo apt -y install nodejs npm
node --version
npm --version
sudo npm i -g aws-cdk
cdk --version
# follow example from: https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#hello_world_tutorial
mkdir simple-s3 && cd simple-s3
cdk init app --language typescript
@xbalaji
xbalaji / aws_cli_env
Created May 10, 2019 18:33
AWS CLI environment setup
#!/bin/bash
# To encrypt
# 1. save the unencrypted data in file called clear.txt
# 2. execute
# gpg -o ./pass.gpg -c ./clear.txt 2>/dev/null
# 3. remove clear.txt
# To decrypt
# 1. gpg -o clear2.txt -d ./pass.gpg 2>/dev/null
# 2. cat clear2.txt