Skip to content

Instantly share code, notes, and snippets.

View ddre54's full-sized avatar

David Rodas ddre54

View GitHub Profile
@ddre54
ddre54 / recover.md
Created December 1, 2022 02:34 — forked from sunapi386/recover.md
How to recover locked out AWS EC2 ssh machine

One time I accidentally messed with the /etc/passwd and locked myself out of being able to SSH into the machine. Since this is a remote machine in AWS I had no way of doing what I'd normally do. Which is attaching a keyboard and monitor and fixing this manually.

To fix, use the AWS EC2 Management page to:

  • spin up a new instance of vanilla ubuntu EC2 (let's call it David)
  • shutdown the locked machine (let's call it Goliath)
  • unmount Goliath's volume
  • attach the volume to David

Then follow this guide: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

@ddre54
ddre54 / download_papertrail_and_process_file.sh
Last active August 18, 2022 18:30
Download all the logs from Papertrail and Process specific logs based on grep expression
# Download all the logs from Papertrail and Process specific logs based on grep expression
# - 1 Download the logs
curl -sH 'X-Papertrail-Token: YOUR-HTTP-API-KEY' https://papertrailapp.com/api/v1/archives.json |
grep -o '"filename":"[^"]*"' | egrep -o '[0-9-]{3,}' |
awk '{
print "url = https://papertrailapp.com/api/v1/archives/" $0 "/download"
print "output = " $0 ".tsv.gz"
}' | curl --globoff --progress-bar -fLH 'X-Papertrail-Token: YOUR-HTTP-API-KEY' -K-
@ddre54
ddre54 / grep_emails_from_file.sh
Created July 10, 2019 21:28
Grep Emails from File
#!/bin/bash
grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" log_file.txt
@ddre54
ddre54 / ssh_multiple_machines.sh
Last active February 27, 2019 19:56
SSH into multiple machines at once and execute commands in all of them
tmux-cssh -i ~/.ssh/<KEY> -u user <HOST1> <HOST2> <HOST3> <HOST4>
@ddre54
ddre54 / release_camera.sh
Last active January 14, 2017 21:18
Skype not being able to connect camera Mac OS
# /bin/bash
sudo killall VDCAssistant
@ddre54
ddre54 / mongodb_all_sparse_indexes.js
Created June 13, 2016 20:22
Mongodb: Prints all the sparse indexes in a db
// Prints all the sparse indexes in the db
db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
indexes.forEach(function(index) {
if (index['sparse']) {
printjson(index);
}
});
});
@ddre54
ddre54 / changing_time_zones.sh
Last active May 13, 2024 02:36
Mac OS X - Terminal commands for changing time zones in the machine
# Useful for testing things that are time zone
# sensitive - like scheduling things
# Get current timezone
sudo systemsetup -gettimezone
# Get list of available timezones
sudo systemsetup -listtimezones
# Set the timezone to the selected timezone
@ddre54
ddre54 / files_using_most_of_the_disk_space.sh
Last active March 10, 2016 21:27
Command to find files using most of the disk space
# /bin/bash
sudo find / -type f -size +10M -exec ls -lh {} \;
# Truncate files that need sudo
sudo truncate -s0 file.txt
@ddre54
ddre54 / redis_keys_clear_pattern_matching.lua
Last active December 13, 2020 16:23
Remove all the keys from redis matching a pattern
--Starting with redis 2.6.0, you can run lua scripts
EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 prefix:*
--For big number of keys
EVAL "local keys = redis.call('keys', ARGV[1]) \n for i=1,#keys,5000 do \n redis.call('del', unpack(keys, i, math.min(i+4999, #keys))) \n end \n return keys" 0 prefix:*
@ddre54
ddre54 / script.sh
Created June 9, 2014 17:42
Terminal pipe process pid into top
#!/bin/sh
top -pid $(ps -A | grep -m1 'unicorn worker' | awk '{print $1}')