Skip to content

Instantly share code, notes, and snippets.

@Adirael
Last active October 27, 2022 17:14
Show Gist options
  • Save Adirael/d2358940a95cbff8c9dca8a1e08878a6 to your computer and use it in GitHub Desktop.
Save Adirael/d2358940a95cbff8c9dca8a1e08878a6 to your computer and use it in GitHub Desktop.
Cheatsheet for devops (jq, bash, aws...)

This is a collection of commands, snippets and tools that I find useful in my day to day. They're mostly stuff related to AWS. You'll find a lot of bash, jq, python...

I'll redact the things I post up here so no private data is shown. Most of this stuff is not going to be usefull as is, but it could be used as a boilerplate for bigger things.

# Create encrypted zip file
zip -e zip_file.zip file_to_encrypt
# List all subnets and returns an iterable list of subnet and free ip addresses
aws ec2 describe-subnets | jq \
'.Subnets[] | {Subnet: (.Tags[] | select(.Key == "Name") | .Value), AvailableIpAddressCount: .AvailableIpAddressCount}' | \
jq -s -c 'sort_by(.Subnet) | .[]'
# Iterate subnets
for subnet in ${SUBNETS}; do # To generate subnets wrap the previous command in the variable: SUBNETS=$(COMMAND)
Name=$(echo $subnet | jq -r '.Subnet')
AvailableIpCount=$(echo $subnet | jq -r '.AvailableIpAddressCount')
echo "${Name} has ${AvailableIpCount} free IPs"
done
# Check SSL certificate expiration
openssl s_client -connect DOMAIN_NAME:443 -servername DOMAIN_NAME 2>/dev/null \
| openssl x509 -noout -dates \
| grep notAfter
# Example output
notAfter=Oct 7 07:27:34 2021 GMT
# Stop app icons from bouncing when a notification arrives
defaults write com.apple.dock no-bouncing -bool TRUE && killall Dock
#!/bin/bash
# Find Tasmota devices in the local network using nmap, sed (gsed) and awk.
for device in $(sudo nmap -sS -p 80 -oG - 192.168.1.0-255 | awk '/80\/open/ {print $2}'); do
PROBE=$(curl -s $device)
if [[ "$PROBE" == *"Tasmota"* ]]; then
NAME=$(echo $PROBE | gsed -n 's/.*<title>\(.*\) \-.*<\/title>.*/\1/ip;T;q')
echo "Tasmota device $NAME found in http://$device"
fi
done
# List of objects to list of strings
cidr_blocks = [
for s in aws_subnet.subnet_list : s.cidr_block
]
# Sed replace inline
sed -i 's/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g' filename
# Find strings starting with hyphen, usefull to find unencrypted ansible vaults using an include pattern
grep -rnw --include PATTERN -- --- .
# Iterate files/folders and run command
for file in $(ls); do echo $file; done
# Sync system date with Google
sudo date --set "$(curl -sI google.com | grep -i '^date:' | cut -d' ' -f2-)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment