Skip to content

Instantly share code, notes, and snippets.

View acsrujan's full-sized avatar
🏠

Srujan acsrujan

🏠
View GitHub Profile
@acsrujan
acsrujan / acsrujan_resume.py
Last active November 27, 2015 07:08
Resume of Srujan Akumarthi (Myself). Python program readable by layman, and also, executable through command line.
'''
If you're viewing it from pdf, original program can be found at: https://gist.github.com/acsrujan/15e211400258871f538a
To run download the file as it is.
Make sure you've python installed. (run python --version in terminal)
python filename.py -h will show the help line. (Make sure to change the file name.)
python filename.py -c will show contacts. and so on.
'''
@acsrujan
acsrujan / install_postgres.sh
Last active December 10, 2015 10:05
Installs postgres 9.3
sudo touch /etc/apt/sources.list.d/pgdg.list
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-9.3 libpq-dev postgresql-contrib-9.3
sudo apt-get autoremove
sudo pg_dropcluster --stop 9.3 main
sudo pg_createcluster --start -e UTF-8 9.3 main
@acsrujan
acsrujan / git_find_big.sh
Created January 21, 2016 07:42
Bash script to find large files in your github.
#!/bin/bash
#set -x
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
@acsrujan
acsrujan / scheduled_ami.sh
Last active March 30, 2016 08:35
Schedule AMI creation and delete 3 days older images.
#!/bin/bash
#---The following is to create AMI of server daily---#
echo "instance-`date +%d%b%y`" > /tmp/ami-name.txt
INSTANCE_ID=$1 #Pass instance id as arguement or change hardcode it here.
aws ec2 create-image --instance-id $INSTANCE_ID --name "`cat /tmp/ami-name.txt`" --description "This is daily auto AMI by Cron" --no-reboot | grep -i ami | awk '{print $2}' > /tmp/ami-id.txt
#---The following is to remove AMIs older than 3 days---#
echo "instance-`date +%d%b%y --date '3 days ago'`" > /tmp/ami-delete.txt
aws ec2 describe-images --filters "Name=name,Values=`cat /tmp/ami-delete.txt`" | grep -i imageid | awk '{ print $2 }' > /tmp/image-id.txt
@acsrujan
acsrujan / deploy_loadbalancer.sh
Last active December 4, 2016 19:11
Deploying to an ELB backed application when you have a deployment script to do on one instance.
$LOAD_BALANCER_NAME=""
Instance_ids=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv"`
for $INSTANCE_ID in ${Instance_ids[@]}:
do
private_ip=`aws ec2 describe-instances --instance-id $id |jq -r '.Reservations[].Instances[] | .PrivateIpAddress'`
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
`ssh $username@$private_ip` < deployment_script.sh
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
done
import platform
import os
import multiprocessing
os_name = platform.system()
print ("os_name:"+os_name)
os_version = platform.version()
print ("os_version:"+os_version)
cpu_architecture = platform.architecture()[0]
@acsrujan
acsrujan / rails_log_parse.sh
Last active March 17, 2016 14:09
Parses rails log file from bash to find out requests which took more than 75sec
arr=```grep -o "in.*ms" $LOG_FILE_NAME | awk '{if ($2-75000ms > 0) print $2}' | sort -r -n``` | for i in $arr; do grep -B 1 $i $LOG_FILE_NAME |awk '{print $2 FS $3}'; echo $i; done
@acsrujan
acsrujan / ELB-detach-attach.sh
Last active September 2, 2016 06:51
Detach and Attach a random instance to an ELB.
#!/bin/bash
LOAD_BALANCER_NAME=$1
Instance_ids_str=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv" |sed 's/\"//g'`
IFS=',' read -a Instance_ids_array <<< "$Instance_ids_str"
for INSTANCE_ID in ${Instance_ids_array[$RANDOM % ${#Instance_ids_array[@]}]}
do
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
done
To find largest inode directory.
```for i in /*; do echo $i; find $i |wc -l; done```
@acsrujan
acsrujan / Instructions.md
Last active June 2, 2016 01:34
nginx load balancing nodejs

Download Repo in /var/www/ folder.