Skip to content

Instantly share code, notes, and snippets.

View chaimackerman's full-sized avatar

Chaim Ackerman chaimackerman

View GitHub Profile
@chaimackerman
chaimackerman / aws-ip-name
Last active November 19, 2020 00:54
Get the EC2 instance name from its private IP address
IP=$1
aws ec2 describe-instances --filters "Name=private-ip-address,Values=$IP" \
--query 'Reservations[0].Instances[0].Tags[?Key==`Name`].Value | [0]'\
--output text
@chaimackerman
chaimackerman / access-log-suffixes
Created June 17, 2020 19:33
access-log-suffixes
cat access_log | sed -E '/\?/s/\?.* HTTP/ HTTP/'| grep -o .......HTTP/1 |
grep -o "\\..* " |
sort | uniq -c | sort -rn
#!/bin/bash
LASTWEEK=$(date -j -v-7d +%Y-%m-%d)
TODAY=$(date -j +%Y-%m-%d)
aws ce get-cost-and-usage --time-period "Start=$LASTWEEK,End=$TODAY" --granularity DAILY --metrics "BlendedCost" |
jq -j '.[][] | .TimePeriod.Start, ": $", .Total.BlendedCost.Amount, "\n"'
@chaimackerman
chaimackerman / es-cnt-media-types.py
Last active February 6, 2020 22:02
Get rough count of media types served by Apache from ElasticSearch
import json
import requests
url = $1/_count"
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
def count_type(type):
payload = {
"query" : {
@chaimackerman
chaimackerman / aws-instance-names
Last active February 4, 2020 22:02
Get AWS Names with Associated InstanceId
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,Tags[?Key==`Name`]]' --output text |
sed -e '$!N;s/\nName./ /' | sort -k4
@chaimackerman
chaimackerman / ls-ec2-servers.sh
Created January 16, 2020 21:28
List the EC2 Servers tagged with "Name"
aws ec2 describe-instances | jq -r '.[][].Instances[].Tags[]? | select(.Key=="Name") | .Value'
@chaimackerman
chaimackerman / ls-host-conns
Last active March 26, 2019 21:32
List Host Connections
netstat -a | awk '/ESTAB/{split($5,a,":");print a[1]}' | sort | uniq -c | sort -rn | head
curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json
@chaimackerman
chaimackerman / utf8_json_str
Created November 23, 2017 18:00
Print utf8 string from python 2.7 script
echo '{ "utf8_str" : "Señor"}' | python -c '
import json,sys,codecs,re
UTF8Reader=codecs.getreader("utf8") # sometimes Rally descriptions are in UTF-8
sys.stdin=UTF8Reader(sys.stdin)
UTF8Writer = codecs.getwriter("utf8")
sys.stdout = UTF8Writer(sys.stdout)
result=json.load(sys.stdin)
print result["utf8_str"]
'
@chaimackerman
chaimackerman / aws-cf-get-distro-id
Last active January 8, 2018 17:50
Get the CloudFront Distribution-Id from its CDN origin
ORIGIN=$1
aws cloudfront list-distributions | jq -r '.[]["Items"][] | select(.DefaultCacheBehavior.TargetOriginId=="S3-"+"'$ORIGIN'") | .Id'