Skip to content

Instantly share code, notes, and snippets.

View epankur's full-sized avatar
🎯
Focusing

epankur

🎯
Focusing
View GitHub Profile
@epankur
epankur / db_backup.sh
Created August 13, 2019 07:59 — forked from NARKOZ/db_backup.sh
MySQL backup shell script
#!/bin/bash
# Shell script to backup MySQL database
# Set these variables
MyUSER="" # DB_USERNAME
MyPASS="" # DB_PASSWORD
MyHOST="" # DB_HOSTNAME
# Backup Dest directory
DEST="" # /home/username/backups/DB
@epankur
epankur / list-iam-keys-by-user-jq.sh
Created June 3, 2021 13:23 — forked from nonrational/list-iam-keys-by-user-jq.sh
list IAM keys / identities (awscli, underscore-cli or jq)
for u in $(aws iam list-users | jq ".Users[].UserName" --raw-output); do
aws iam list-access-keys --user $u | jq '.AccessKeyMetadata[] | .UserName + ":" + .AccessKeyId' ;
done
#!/bin/bash -x
yum -y update --security
##########################
## ENABLE SSH RECORDING ##
##########################
# Create a new folder for the log files
mkdir /var/log/bastion
@epankur
epankur / list.txt
Created June 30, 2021 19:43 — forked from shortjared/list.txt
List of AWS Service Principals
a4b.amazonaws.com
acm-pca.amazonaws.com
acm.amazonaws.com
alexa-appkit.amazon.com
alexa-connectedhome.amazon.com
amazonmq.amazonaws.com
apigateway.amazonaws.com
appflow.amazonaws.com
application-autoscaling.amazonaws.com
appstream.application-autoscaling.amazonaws.com
@epankur
epankur / delete_branches_older_than.sh
Created February 17, 2022 11:41 — forked from njames/delete_branches_older_than.sh
Script to delete branches older than 6 months old, ignore local vs remote errors.
#!/bin/sh
ECHO='echo '
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'main$\|develop$'); do
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "1 month ago" | wc -l)" -eq 0 ]]; then
if [[ "$DRY_RUN" = "false" ]]; then
ECHO=""
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git branch -d "${local_branch_name}"
@epankur
epankur / newcert.py
Created June 1, 2022 06:34 — forked from Zeerg/newcert.py
Python script to generate CSR/Self Signed Cert. Needs pyOpenssl and python-whois
#!/usr/bin/python
from OpenSSL import crypto
import os
import sys
import datetime
import whois
#Variables
TYPE_RSA = crypto.TYPE_RSA
TYPE_DSA = crypto.TYPE_DSA
@epankur
epankur / GetEC2RunTime.py
Created August 22, 2022 07:34 — forked from sudharsans/GetEC2RunTime.py
Python Boto3 script to find the number of minutes an instance has been running.
##
# Python Boto3 script to find the number of minutes an instance has been running.
## Output
# i-00asdf5xxx50c96aa 84 days, 13:17:51.468559
# i-0260a1fxxx27ec894 6 days, 13:48:04.468643
# i-0acxxx6c630af322 13 days, 12:13:00.468659
# i-069bxxxd41bf975eb 19:42:08.468670
import boto3
from datetime import datetime, timezone
@epankur
epankur / send_pdf_with_boto_ses.py
Created September 9, 2022 09:00 — forked from jniva/send_pdf_with_boto_ses.py
send PDF attachment with boto and SES
''' quick example showing how to attach a pdf to multipart messages
and then send them from SES via boto
'''
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto
@epankur
epankur / function.py
Created October 14, 2022 07:50 — forked from brandond/function.py
Python script to auto-tag AWS EBS Snapshots and Volumes using AMI and Instance tags
import copy
import logging
import os
import boto3
logging.basicConfig(level=os.environ.get('LOG_LEVEL', 'INFO'))
ec2 = boto3.client('ec2')
logger = logging.getLogger(__name__)
@epankur
epankur / tag-vols-snaps.py
Created October 14, 2022 07:50 — forked from danpritts/tag-vols-snaps.py
Automatically tag EC2 snapshots and volumes based on their attached AMIs/instances
# most credit to the original: https://gist.github.com/brandond/6b4d22eaefbd66895f230f68f27ee586
# Tag snapshots based on their associated AMI and volumes based on attached instance.
# format:
# (AMI:db5|db5) /dev/sda1 (1/4)
# (AMI:db5|db5) /dev/sdb (2/4)
# Best practice: create IAM user
# Simplest privilege to get it to work with reasonable security: use predefined policy "ReadOnlyAccess"