Skip to content

Instantly share code, notes, and snippets.

Syntax: Enfo_iam.sh
Options:
-c|--cache-dir <dir> Use a specifc report cache dir. Default is /var/cache/Enfo_iam/Enfo_iam_report_*.
-d|--debug Debug output
-E|--exit-on-error Stop script on aws error
-e|--error Error output
-f|--fresh-data Get a new report, automatically saved as last cache when finished
Works well with -q for cronjobs or with '-q -d' for debug
-F|--fields <comma separated fileds list>
Comma separated columns list (see below)
#!/bin/bash
# Syntax: ec2_kamino.sh <source instance 'Name' tag> [target new instance 'Name' tag].
# If target name is not given <source name>-clone is used.
# Description: Builds a temporary template from a given instance and runs the latest found ami from that template.
# New instance settings can be overriden by $overrides.
# AMI selection is filtered by $ami_select.
# New instance in also tagged with 'clone-source' tag of source instance.
# New instance EBS volumes are tagged with the same 'Name' tag of the new instance.
# Written by Shoko, Oct2019.
# Requires: jq, awscli, standard gnu utils.
@shokoe
shokoe / 1. ec2_cpu_burst.sh
Last active October 13, 2019 17:39
A Nagios/Naemon script for monitoring CPU burst status for all T2 and T3 EC2 instances in an account
#!/bin/bash
. /opt/EC2ulz/EC2ulz.sh
#max_age=660
max_age=720
balance_warn=50
balance_crit=20
# history of metrics to get in minutes
metric_time=15
# Couldn't find an API for this data so it's hard coded :(
@shokoe
shokoe / na_stat.sh
Created May 16, 2018 12:45
naemon status on liner
mklive_cmd='/usr/bin/naemon-unixcat /omd/sites/magisto/tmp/run/live'; while true; do O=$((echo "Host,Check,Status,Interval,Delay,Exec"; echo -e 'GET services\nColumns: host_name description last_state check_interval last_check execution_time' | $mklive_cmd | awk -F';' -v N=`date +%s` 'N-$5 > $4*60 {printf "%s,%s,%d,%d,%d,%.2f\n", $1, $2, $3, $4*60, N-$5, $6}') | column -s , -t); clear; date; echo; uptime; echo; free -m; echo; echo "$O"; echo " Count:`echo \"$O\" | wc -l`"; sleep 10; done
@shokoe
shokoe / csv_header.sh
Last active April 14, 2018 12:30
Print csv file by headers
#!/bin/bash
# Syntax: csv_header.sh "<space delimited head names>" "<empty string replacment>"
awk -F, -v E="${2:--}" -v H="$1" -v D="^^^" '
NR==1 {
split(H,h," ")
for (i=1; i<=NF; i++) {
f[$i] = i
}
for (i in h) {
printf "%s%s", h[i], D
@shokoe
shokoe / check_ec2_lb_health.sh
Last active September 28, 2021 12:17
AWS ELB/ALB Nagios check script
#!/bin/bash
region="--region us-east-1"
profile=""
elb_name=""
alb=false
while [[ $# > 0 ]]; do
key="$1"
case $key in
--elb) elb_name="${2/*lb./}";;
@shokoe
shokoe / aws_billing_grafana.sh
Last active September 28, 2021 12:17
Export aws billing info to grafana. Uses AWS billing info from S3. Just activate logs in billing and change the 'f' var in the script.
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
netcat=$(which nc)
host='<carbon IP>'
port='2003'
nc_cmd="$netcat -q0 $host $port"
get_month(){
f="<your id>-aws-billing-detailed-line-items-with-resources-and-tags-${1}"
@shokoe
shokoe / aws_billing_grafana.sh
Created March 21, 2018 18:36
Export aws billing info to grafana. Uses AWS billing info from S3. Just activate logs in billing and change the 'f' var in the script.
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
netcat=$(which nc)
host='<carbon IP>'
port='2003'
nc_cmd="$netcat -q0 $host $port"
get_month(){
f="<your id>-aws-billing-detailed-line-items-with-resources-and-tags-${1}"
@shokoe
shokoe / mtail.sh
Created March 21, 2018 10:38
Tail for server cluster shell script. Tails same file on multiple servers using EC2ulz.
#!/bin/bash
ssh_ops='-fn -o ConnectTimeout=1 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR'
print_help(){
echo "Syntax: $0 <instance grep string> <log file> [grep regex]
example: mtail.sh 'proc-app-fronts?|proc-app-back001' /var/log/apache2/access.log '404|500'
exit mtail with Ctrl-C"
}
[ $# -lt 2 ] && print_help && exit
@shokoe
shokoe / aws_inspector_cron.sh
Last active April 14, 2023 11:39
Executes AWS Inspector run, export full findings csv file from last completed run, compile a concise counters report including severity and package aggregates by hostname. Full and aggregated report are uploaded to S3.
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin
log="/var/log/aws_inspector/aws_inspector_export_rep.log"
template_arn='arn:aws:inspector:us-east-1:XXXXXXXXXXXX:target/xxxxxxxxxx/template/xxxxxxxxxx'
wait_sec='5400'
log_out(){
(($verifymon)) &&\
echo -e "`date +'%Y-%m-%d %H:%M:%S'` (pid $$) -- $1" >> $log ||\
echo -e "`date +'%Y-%m-%d %H:%M:%S'` (pid $$) -- $1" | tee -a $log