Skip to content

Instantly share code, notes, and snippets.

View srkiNZ84's full-sized avatar

Srđan (Serge) Đukić srkiNZ84

View GitHub Profile
@srkiNZ84
srkiNZ84 / archive_repos_git.sh
Last active July 28, 2020 02:44
Couple of bash scripts I wrote to archive Cloudforge repos
#!/bin/bash
filename="git_repo_list.txt"
while read repo
do
echo "Starting to Archive repository '$repo'"
echo "Git checking out repository '$repo'"
git clone $repo
repoShortName=$(echo $repo | grep -E -o '([^\/\.]+).git$')
@srkiNZ84
srkiNZ84 / check_acm_cert_duplicates.sh
Last active August 4, 2020 08:54
Bash script to check whether the certificate you've got locally is already in AWS Certificate Manager or not (based on md5sum and tags)
#!/bin/bash
CURRENT_CERT_MD5SUM=af375610c480018271caa1b624c838b3
for acmCertificate in $(aws acm list-certificates | jq -r .CertificateSummaryList[].CertificateArn)
do
echo "Cert ARN is $acmCertificate"
ACM_CERT_MD5SUM=$(aws acm list-tags-for-certificate --certificate-arn $acmCertificate | jq -r '.Tags[] | select(.Key | contains("Md5SumCert")) | .Value')
if [[ "$CURRENT_CERT_MD5SUM" == "$ACM_CERT_MD5SUM" ]]
then
@srkiNZ84
srkiNZ84 / update_elb_certificate_letsencrypt_route53.sh
Last active August 17, 2021 15:21
Bash script to automate the renewal of LetsEncrypt certificates using DNS authentication with Route53 and then updating the load balancers
#!/usr/bin/bash
# pre-requisites:
# apt install python3-pip awscli
# pip3 install certbot certbot-dns-route53 awscli
# mkdir .certbot/{config,work,logs}
# IAM policy attached to EC2 instance with:
# - route53:ListHostedZones
# - route53:GetChange
# - route53:ChangeResourceRecordSets
@srkiNZ84
srkiNZ84 / copy-ssm-params.py
Created September 22, 2020 03:12
Copy SSM parameters from one path in SSM to another
#!/usr/bin/python3
import boto3
session = boto3.Session(profile_name='foobar')
client = session.client('ssm')
fromPath = "/production/"
toPath = "/uat/"
@srkiNZ84
srkiNZ84 / bash-child-cgroups.sh
Last active October 7, 2020 22:12
Simple demonstration of using Linux cgroups to set limits on the number of processes
#!/bin/bash
# PREREQUISITES: On Ubuntu 18.04 need to make sure that the "libcgroup1" and "cgroup-tools" packages are installed
MAXNUMPROCS=11
MAXNUMCHILDPROCS=8
PARENTGROUP=sandwich
# Create the parent cgroup
##OPTIONAL: This part should be already there on more recent Linux distributions
@srkiNZ84
srkiNZ84 / gke_users.csv
Last active March 16, 2021 01:14
Script to make GCP service accounts and generate kubernetes authentication files for them
John Wayne [email protected] GKE service account for John
Barbara Streisand [email protected] GKE service account for Barbara
@srkiNZ84
srkiNZ84 / app.js
Created May 3, 2021 11:25
NodeJS HelloWorld
const express = require('express')
const app = express()
const port = 3000
const NAME = process.env.NAME || "World"
app.get('/', (req, res) => {
res.send('Hello ' + NAME + '!')
})
app.listen(port, () => {

Bash Snippets

Find AWS EC2 instance by id

aws --profile dev ec2 describe-instances | jq '.Reservations[].Instances[] | select(.InstanceId == "i-0abcdefe412345678")'
@srkiNZ84
srkiNZ84 / get_instance_ips.sh
Created June 11, 2021 02:04
Get AWS EC2 instances using AWS CLI query param
#!/bin/bash
aws --profile dev \
ec2 describe-instances \
--query 'Reservations[].Instances[].[InstanceId,Tags[?Key==`Name`].Value[],NetworkInterfaces[].Association.{IP:PublicIp}]'
@srkiNZ84
srkiNZ84 / list-upgradable.py
Last active March 11, 2022 04:48
Python script to get list of installed packages that have upgrades and output in JSON
#!/usr/bin/python3
# NOTE: Requires the python3-apt package
import apt
import apt_pkg
import json
need_upgrade = []