Skip to content

Instantly share code, notes, and snippets.

View MrHassanMurtaza's full-sized avatar
🎯
Focusing

Hassan Murtaza MrHassanMurtaza

🎯
Focusing
View GitHub Profile
@MrHassanMurtaza
MrHassanMurtaza / check-k8s-resources.sh
Created July 1, 2022 08:49
Check if resources got created in kubernetes
#!/bin/bash
while : ; do
kubectl get [your thing] && break
sleep 1
done
@MrHassanMurtaza
MrHassanMurtaza / remove-pv.sh
Created June 30, 2022 10:35
Remove PVC from Namespace
#!/bin/bash
set -ex
for i in $(k get pvc | awk '{if(NR>1)print $1}');
do
kubectl delete pvc $i
done
@MrHassanMurtaza
MrHassanMurtaza / remove-claimref-pv.sh
Last active June 30, 2022 10:20
Remove claimRef from all persistent volumes using kubectl
#!/bin/bash
set -ex
for i in $(kubectl get pv | awk '{print $1}');
do
kubectl patch pv $i --type=json -p '[{"op": "remove", "path": "/spec/claimRef"}]'
done
@MrHassanMurtaza
MrHassanMurtaza / aws_delete-default-vpc.sh
Created April 8, 2022 00:39 — forked from jokeru/aws_delete-default-vpc.sh
Script to delete all AWS default VPCs from all regions using AWS CLI
#!/usr/bin/env bash
if [ "$AWS_PROFILE" = "" ]; then
  echo "No AWS_PROFILE set"
  exit 1
fi
for region in $(aws ec2 describe-regions --region eu-west-1 | jq -r .Regions[].RegionName); do
@MrHassanMurtaza
MrHassanMurtaza / assume-role.sh
Last active December 22, 2022 17:59
Assume AWSControlTowerExecution from management account
#!/bin/bash
export AWS_REGION="us-west-2"
account_id=$1
temp_role=$(aws sts assume-role \
--role-arn "arn:aws:iam::${account_id}:role/AWSControlTowerExecution" \
--role-session-name "aws-ct-mgmt")
unset AWS_ACCESS_KEY_ID
@MrHassanMurtaza
MrHassanMurtaza / user_data.sh
Created October 4, 2021 13:49
User data with ansible
#!/bin/sh
#exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
sudo apt update -y
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansible python3-pip vim git
pip3 install boto3 botocore
@MrHassanMurtaza
MrHassanMurtaza / reboot-ec2.py
Created June 16, 2021 10:58
reboot ec2 instance using lambda
import json
import boto3
EC2_INSTANCE_ID="i-xxxxxx"
ec2_handle = boto3.client(
'ec2'
)
def lambda_handler(event, context):
@MrHassanMurtaza
MrHassanMurtaza / s3-latest-object.sh
Last active June 16, 2021 10:26
Getting latest s3 bucket's object
#!/bin/bash
set -x
set -e
S3_BUCKET=""
S3_PREFIX=""
OBJECT="$(aws s3 ls s3://$S3_BUCKET/$S3_PREFIX | sort | tail -n 1 | awk '{print $4}')"
[ -z "$OBJECT" ] && echo "Object not found in S3 Bucket." && exit 1
@MrHassanMurtaza
MrHassanMurtaza / keycloak-export-docker.sh
Last active July 8, 2024 19:51
Keycloak export in Docker and Exit
# If something goes wrong, this script does not run forever but times out
TIMEOUT_SECONDS=300
# Logfile for the keycloak export instance
LOGFILE=/tmp/standalone.sh.log
# destionation export file
JSON_EXPORT_FILE=/tmp/realms-export-single-file.json
rm -f ${LOGFILE} ${JSON_EXPORT_FILE}
# Start a new keycloak instance with exporting options enabled.
@MrHassanMurtaza
MrHassanMurtaza / keycloak-import-docker.sh
Last active February 9, 2022 14:33
Keycloak Import in Docker and Exit
#!/bin/sh
# If something goes wrong, this script does not run forever but times out
TIMEOUT_SECONDS=300
# Logfile for the keycloak export instance
LOGFILE=/tmp/standalone.sh.log
# destionation export file
JSON_IMPORT_FILE=/opt/jboss/keycloak/imports/realm-export.json