Skip to content

Instantly share code, notes, and snippets.

View alexandrerocco's full-sized avatar
😁

Alexandre Rocco alexandrerocco

😁
View GitHub Profile
@alexandrerocco
alexandrerocco / aws-key-pair-find-delete.sh
Created November 29, 2021 23:27
Lists unused AWS key pair and delete if needed
# List key pairs on the account
aws ec2 describe-key-pairs --query 'KeyPairs[*].KeyName' --output table
# Find instances that uses a key pair you found out above
aws ec2 describe-instances --filters Name=instance-state-name,Values=running Name=key-name,Values="KP-NAME" --query 'Reservations[*].Instances[*].InstanceId'
# If you get an empty response, you can opt to delete it with:
aws ec2 delete-key-pair --key-name KP-NAME
@alexandrerocco
alexandrerocco / delete-test-queues.sh
Created September 6, 2021 13:44
Deletes test or old AWS SQS queues that matches the prefix
prefix=your-queue-prefix"
region="your-region"
queues=$(aws sqs list-queues --queue-name-prefix $prefix --region $region)
for q in ${queues[@]}
do
if [ "${q:0:1}" == "\"" ]; then
x=${q:1:${#q}-3}
if [ $x != "QueueUrls" ]; then
aws sqs delete-queue --region $region --queue-url $x
fi
@alexandrerocco
alexandrerocco / fix-unassigned-shards.sh
Last active December 21, 2015 10:05
Fix unassigned shards in Elasticsearch, you may lose data!
#!/bin/bash
NODE="YOUR NODE NAME"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands": [
{
@alexandrerocco
alexandrerocco / find_iam_user.py
Last active August 29, 2015 14:05 — forked from OnlyInAmerica/find_iam_user.py
Finds an AWS IAM user that corresponds to the access key passed by the command line parameter.
# Find the IAM username belonging to the command line parameter
# Useful for finding IAM user corresponding to a compromised AWS credential
# Requirements:
#
# Environmental variables:
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
# python:
# boto
@alexandrerocco
alexandrerocco / install-nodejs-ubuntu.sh
Created September 2, 2013 13:47
Install nodejs on Ubuntu. Works on any release including Ubuntu 12.04 LTS, Ubuntu 12.10 and Ubuntu 13.04.
#!/bin/bash
apt-get update
apt-get install -y python-software-properties software-properties-common
add-apt-repository ppa:chris-lea/node.js
apt-get update
apt-get install nodejs
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get -y install python-software-properties
sudo apt-add-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get -y install nodejs
# Install git to get statsd
sudo apt-get -y install git
@alexandrerocco
alexandrerocco / mongodb-single-instance.sh
Created August 13, 2013 14:27
Install a standalone MongoDb server with an attached volume
#!/bin/bash
sudo -s
yum -y update
yum -y install mdadm sysstat
cat <<EOF > /etc/yum.repos.d/10gen.repo2
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
@alexandrerocco
alexandrerocco / install redmon on centos.sh
Created August 5, 2013 21:16
Install redmon on CentOS via rvm
sudo -s
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm requirements
rvm install 1.9.3
rvm use 1.9.3 --default
# ruby -v
# should be ruby 1.9.3
rvm rubygems current
# gem -v
@alexandrerocco
alexandrerocco / install-node-centos.sh
Last active December 20, 2015 03:39
Install nodejs from source on Centos
sudo -s
## dependencies to build
yum -y groupinstall "Development Tools"
## download and build
cd /opt
wget http://nodejs.org/dist/node-latest.tar.gz
tar zxf node-latest.tar.gz
cd node-latest
./configure
@alexandrerocco
alexandrerocco / install-htop.sh
Last active May 8, 2022 09:18 — forked from magemore/gist:4499587
Amazon Linux - Install htop
# update
sudo yum -y update
sudo yum -y upgrade
# enable EPEL6 by changing enabled=0 -> enabled=1
sudo vim /etc/yum.repos.d/epel.repo
# install htop
sudo yum install htop